解雇ViewController动画不动画ViewController

dismissViewControllerAnimated not animating ViewController

我想在屏幕上滑入一个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];
}

你能试着改变这一行吗:

[presenterVC dismissViewControllerAnimated:NO completion:nil];

对于这个:

[presenterVC dismissViewControllerAnimated:YES completion:nil];

更新

确保您在 Main Thread

上调用静态函数