问题与UIView的自动布局动画
我有一个的UIView
从顶部苍蝇当我打开该视图控制器。我已经将的UIView
的Y约束至-200和视图加载时,下面的叫,一切工作正常:
I have a UIView
that flies from the top when I open that view controller. I've set the Y Constraint of the UIView
to -200 and when the view loads, the below is called and everything works fine:
- (void)updateViewConstraints
{
[super updateViewConstraints];
self.popUpViewYConstraint.constant = 37.0f;
self.closeButtonYConstraint.constant = 28.0f;
[self.popUpBaseView setNeedsUpdateConstraints];
[self.closeButton setNeedsUpdateConstraints];
[UIView animateWithDuration:0.25f animations:^{
[self.popUpBaseView layoutIfNeeded];
[self.closeButton layoutIfNeeded];
[self.view layoutIfNeeded];
}];
}
但现在我有一个关闭按钮应该动画的UIView
回-200的位置,然后从屏幕视图控制器。但热闹是不是正在发生。视图控制器是越来越直接删除。下面是我在做什么:
But now I have a close button that should animate the UIView
back to the -200 position and then remove the view controller from the screen. But this animation is not taking place. The view controller is getting removed directly. Here's what I'm doing:
- (IBAction)closePressed:(id)sender
{
NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
self.navigationController.viewControllers = navigationArray;
[UIView animateWithDuration:2.0f animations:^{
self.popUpViewYConstraint.constant = -200.0f;
[self.popUpBaseView layoutIfNeeded];
} completion:^(BOOL finished){
[navigationArray removeObjectAtIndex: 1];
[self.baseView removeFromSuperview];
[self.view removeFromSuperview];
}];
}
我提到this链接。这似乎是为他们工作,但对我不起作用。
请帮助。
I referred to this link. It seems to be working for them but doesn't work for me. Please help.
这个怎么样
- (IBAction)closePressed:(id)sender
{
NSMutableArray *navigationArray = [[NSMutableArray alloc]:initWithArray:self.navigationController.viewControllers];
self.navigationController.viewControllers = navigationArray;
// I am sure the constant should be set outside the animation block. It won't happen until next run loop, which will be inside the block.
self.popUpViewYConstraint.constant = -200.0f;
// setNeedsUpdateConstraints should be called on the view to which the constraint is added, not the view affected by the constraint.
[self.baseView setNeedsUpdateConstraints];
[UIView animateWithDuration:2.0f animations:^{
// I think this should be topmost view
[self.view layoutIfNeeded];
} completion:^(BOOL finished){
[navigationArray removeObjectAtIndex: 1];
[self.baseView removeFromSuperview];
[self.view removeFromSuperview];
}];
}