[英]How to wait for an animation to finish in viewDidDisappear?
I want to hide the navigation bar using animation before I let a UIViewController disappear. 我想在让UIViewController消失之前使用动画隐藏导航栏。 Therefore I have implemented the following: 因此我实施了以下内容:
-(void) viewWillDisappear:(BOOL) animated {
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationCurveEaseOut
animations:^{
[self.navigationController setNavigationBarHidden:YES];
}
completion:^(BOOL finished){
NSLog(@"animation finished");
}];
[super viewWillDisappear:animated];
}
The problem is that the viewWillDisappear will continue to execute and just return and the whole view will go away before the animation finishes. 问题是viewWillDisappear将继续执行并返回,整个视图将在动画结束前消失。 How can I stop the method from returning before the completion of the animation (where "animation finished" gets printed). 如何在动画完成之前(在“动画完成”打印的情况下)停止方法返回。
viewWillDisappear:animated
is in essence a courtesy notification. viewWillDisappear:animated
本质上是礼貌通知。 It's just telling you what is imminent before it happens. 它只是在它发生之前告诉你即将发生的事情。 You can't actually block or delay the disappearance of the view. 您实际上无法阻止或延迟视图的消失。
Your best solution would be to create a category on UINavigationController
that creates methods such as (untested): 您最好的解决方案是在UINavigationController
上创建一个类别,用于创建(未经测试)等方法:
- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated {
[UIView transitionWithView:viewController.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationCurveEaseOut
animations:^{
[self.navigationController setNavigationBarHidden:NO];
}
completion:^(BOOL finished){
NSLog(@"animation finished");
[self pushViewController:viewController animated:animated];
}];
}
- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated {
[UIView transitionWithView:self.visibleViewController.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationCurveEaseOut
animations:^{
[self.navigationController setNavigationBarHidden:YES];
}
completion:^(BOOL finished){
NSLog(@"animation finished");
[self popViewControllerAnimated:animated];
}];
}
You could then call these on instead of 然后你可以打电话给这些而不是
- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated
and 和
- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated
respectively. 分别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.