ios - 使用自定义动画呈现 ViewController

标签 ios objective-c animation uiviewcontroller

我正在使用 foll 呈现一个 View Controller 。代码:

VC_B * b = [[VC_B alloc] init...];
[self presentViewController:b animated:YES completion:nil];

我正在尝试为 View Controller 的外观设置动画:传入的 VC 应该从覆盖当前显示的 VC 的顶部向下滑动。以下 this解决方案使它解决了一个问题:在传入的 VC 出现在屏幕上之前,当前的 VC 消失了。有办法解决这个问题吗?也许有另一种解决方案可以实现这种效果。

最佳答案

试试这段代码:

CreateNewViewController *newViewController = [[CreateNewViewController alloc]initWithNibName:@"CreateNewViewController" bundle:nil];

    CATransition *transition = [CATransition animation];
    transition.duration = 0.05;
    transition.timingFunction = [CAMediaTimingFunction      
    functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type =kCATransitionMoveIn;
    transition.subtype =kCATransitionFromTop;

    transition.delegate   = self;

    [self presentModalViewController:newViewController animated:NO];
    [self.view insertSubview:newViewController.view atIndex:0];

    [self.view.layer addAnimation:transition forKey:nil];

希望这对您有所帮助。

关于ios - 使用自定义动画呈现 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16377799/

相关文章:

objective-c - 以步进增量滚动水平 UIScrollView?

ios - iframe 自动全屏使状态栏消失

ios - 如何可靠地阻止 Objective-C 中的重复动画调用?

iphone - NSMutableArray 问题

animation - 如何为 svg 的 animateTransform 设置原点

javascript - 如何在 Velocity.js 中反转步骤

iphone - 来自 Cydia 的应用程序的 Settings.bundle 和钥匙串(keychain)不起作用

iphone - AFNetworking 2.0 向 GET 请求添加 header

html - 在 CSS 动画后显示网站

iphone - "__workq_kernreturn"在 iOS 崩溃日志中或当您暂停应用程序执行时表示什么?