ios - dismissViewControllerAnimated : completion: happens instantly unless I kludge it

标签 ios uiviewcontroller modalviewcontroller

我有一个以模态方式显示的自定义 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/

相关文章:

android - 在 Crashlytics 中查看特定问题的所有崩溃

ios - 如何使用 ZipKit 在 iOS 中压缩目录?

ios - UIScrollView 嵌入导航 Controller 时表现不同

ios - 对于 iOS,将 ViewController.xib 自定义类更改为另一个类意味着什么?

ios8 - 模态视图 Controller 被解除后iOS 8键盘解除延迟

iOS8 - 防止在呈现 viewController 时旋转

ios - 如何从模态视图中弹出 ToRootViewController?

ios - 淡出 UICollectionView 中的项目

ios - 创建都继承自 BaseViewController 的 TableViewController 和 UIViewController