我有一个以模态方式显示的自定义 UIViewController。我称它为 mainMenu
。
它有自己可爱的小过渡动画,可以使 View 滑出屏幕。当我想关闭它时,我想调用自定义动画,然后在完成后实际关闭它。看起来这应该可行:
- (void) dismissCustomViewController {
[mainMenu slideMenuPanelsAway];
[self dismissViewControllerAnimated:YES completion:nil];
}
但是,在我看到自定义幻灯片之前,这会使 View Controller 立即消失。
让 View Controller 等到菜单消失后再消失的正确方法是什么?
我已经尝试了很多东西。我只找到一种方法让它工作:
- (void) dismissCustomViewController {
[mainMenu slideMenuPanelsAway];
[self performSelector:@selector(dismissController) withObject:nil
afterDelay: 2.0f];
}
(我编写了一个名为 dismissController
的自定义方法只是为了让选择器更易于使用,它基本上只是调用 [self dismissViewControllerAnimated:YES completion:nil];
。)
使用手动延迟设置而不是实际将其基于动画的完成似乎很糟糕。一定有更好的方法,不是吗?
最佳答案
使用 animateWithDuration:animations:completion:,并在动画 block 中执行“slidey stuff”并在完成 block 中执行解雇操作。
[UIView animateWithDuration:.5 animations:^{
//Your custom animation stuff here
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
关于ios - dismissViewControllerAnimated : completion: happens instantly unless I kludge it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18276013/