dismissViewControllerAnimated不动画ViewController

时间:2017-07-28 08:11:51

标签: ios objective-c model-view-controller uiviewcontroller core-animation

我想在屏幕中滑入一个ViewController,然后在某些时候将其滑出并返回到呈现的ViewController。 我使用MainViewController中的代码来启动模态,然后将其解除。

为什么解雇幻灯片动画 无效?

// Present a React Component sliding from the right on top of current ViewController
+ (void)presentSlidingFromRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
    CATransition *transition = [[CATransition alloc] init];
    transition.duration = 1;
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
    [presenterVC presentViewController:presented animated:NO completion:nil];
}

// Dismiss a React Component sliding to the right
+ (void)dismissSlidingToRight:(UIViewController*)presented onViewController:(UIViewController*)presenterVC {
    CATransition *transition = [[CATransition alloc] init];
    transition.duration = 3;
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromLeft;
    [presenterVC.view.window.layer addAnimation:transition forKey:kCATransition];
    [presenterVC dismissViewControllerAnimated:NO completion:nil];
}

1 个答案:

答案 0 :(得分:2)

您可以尝试更改此行:

[presenterVC dismissViewControllerAnimated:NO completion:nil];

这个:

[presenterVC dismissViewControllerAnimated:YES completion:nil];

<强>更新

确保您在Main Thread

上调用静态函数