gpt4 book ai didi

iphone - 如何等待动画在 viewDidDisappear 中完成?

转载 作者:可可西里 更新时间:2023-11-01 04:48:29 26 4
gpt4 key购买 nike

我想在让 UIViewController 消失之前使用动画隐藏导航栏。因此我实现了以下内容:

-(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];
}

问题是 viewWillDisappear 会继续执行并返回,整个 View 会在动画结束前消失。我怎样才能阻止方法在动画完成之前返回(打印“动画完成”的地方)。

最佳答案

viewWillDisappear:animated 本质上是一个礼貌的通知。它只是在它发生之前告诉你即将发生的事情。您实际上无法阻止或延迟 View 的消失。

您最好的解决方案是在 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];
}];
}

然后你可以调用这些而不是

- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated

- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated

分别。

关于iphone - 如何等待动画在 viewDidDisappear 中完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9071386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com