ios - dismissViewControllerAnimated 不为 ViewController 设置动画

标签 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];
}

最佳答案

你可以尝试改变这一行:

[presenterVC dismissViewControllerAnimated:NO completion:nil];

对于这个:

[presenterVC dismissViewControllerAnimated:YES completion:nil];

更新

确保您在 Main Thread 上调用静态函数

关于ios - dismissViewControllerAnimated 不为 ViewController 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45368222/

相关文章:

c# - 我想使用 jquery 将行插入到 WebGrid 中

php - 您将如何设置一个小型 MVC 结构?

java - 在基于表单的身份验证中设置 UserPrincipal

ios - 在 Objective-C 中对文本应用阴影效果

iphone - 替换出现之间的字符串

ios - 应如何为推送通知服务设置代码签名?

iphone - 准确无缝地将文本拆分为两个 UILabel

ios - 如何使用不接受实时输入的 CoreML 在 Swift 中创建一个简单的相机应用程序?

ios - 当 UITableViewController 不是类类型时,如何快速获取 self.tableView.reload Table()

ios - 将字典数组转换为字典并初始化模型