代码之家  ›  专栏  ›  技术社区  ›  Ben Gotow Dmitry Nogin

我可以提高presentModalViewController的动画速度吗?

  •  2
  • Ben Gotow Dmitry Nogin  · 技术社区  · 17 年前

    我正在编写一个绘图应用程序,当用户单击工具栏中的项目时,它会显示一个工具视图控制器。然而,我的几个beta测试人员报告说,这些工具打开得太慢了。我正在使用标准的presentModalViewController:animated:call来显示工具,我尝试将其包装在这样的代码块中以加快速度:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 0.1];
    [self presentModalViewController:settings animated:YES];
    [UIView commitAnimations];
    

    在这之前有没有人愿意提供一些建议?我会很感激的!

    2 回复  |  直到 17 年前
        1
  •  13
  •   AngraX    14 年前

    已编辑:为iOS 5及更高版本添加了另一个控制器包含选项。

    另一个解决方案是设置层的时间空间。

    这是通过CALayer的speed属性实现的。要减慢动画速度,可以使用:

    MytransparentVCViewController *vc = [[MytransparentVCViewController alloc] initWithNibName:@"MytransparentVCViewController" bundle:nil];
    // Makes all animations 10 times slower
    // To speed it up, set it to multiples of 1: 2 is 2 times faster, 3 is 3 times faster etc
    vc.view.layer.speed = 0.1; 
    [self presentModalViewController:vc animated:YES];
    

    层的速度不是绝对值,而是该层父时间空间的函数(当然,除非该层位于层层次结构的根中)。例如,将层的速度设置为2时,其动画的运行速度将是该层父级动画的两倍。

    另一种选择是使用视图控制器包含。(仅限iOS 5及更高版本)

    http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW81 .

    通过UIViewController从ViewController:到ViewController:持续时间:选项:动画:完成:的转换,您可以完全控制动画。

        2
  •  1
  •   Community Mohan Dere    9 年前

    here .

    你也可以使用这种技术来改变速度,但在我的实验中,它是在空白背景下进行的,正如你所建议的那样。

    推荐文章