0

我有一个以模态方式显示的自定义 UIViewController。我正在调用它mainMenu

它有自己可爱的小过渡动画,可以让它的视图滑出屏幕。当我想关闭它时,我想调用自定义动画,然后在完成后实际关闭它。看起来这应该有效:

- (void) dismissCustomViewController {
    [mainMenu slideMenuPanelsAway];
    [self dismissViewControllerAnimated:YES completion:nil];
}

但是,这会使视图控制器在我看到自定义的滑动内容之前立即消失。

让视图控制器等到菜单消失后再消失的正确方法是什么?

我已经尝试了很多东西。我只找到了一种使它起作用的方法:

- (void) dismissCustomViewController {
    [mainMenu slideMenuPanelsAway];
    [self performSelector:@selector(dismissController) withObject:nil 
       afterDelay: 2.0f];
}

(我写了一个自定义方法,dismissController只是为了让选择器更容易使用,它基本上只是调用[self dismissViewControllerAnimated:YES completion:nil];.)

使用手动延迟设置而不是实际基于动画的完成似乎很糟糕。一定有更好的方法,不是吗?

4

1 回答 1

3

Use animateWithDuration:animations:completion:, and do the "slidey stuff" in the animation block and do the dismissal in the completion block.

[UIView animateWithDuration:.5 animations:^{
        //Your custom animation stuff here

    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
于 2013-08-16T14:51:58.213 回答