Can I increase the animation speed of presentModalViewController?

别说谁变了你拦得住时间么 提交于 2019-12-04 09:59:47
zpasternack

A similar question is asked here.

You can also change the speed using this technique, but in my experimentation, it does so over a blank background, as you've suggested.

Edited: added another option with controller containment for iOS 5 and later.

Another solution is to set the layer's time space.

This is done through the speed property of CALayer. To slow the animation down, one could use:

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];

Note that the proposed solution in the linked post will not work if your objective is to change the animation speed of the modal view controller you are about to present (for example if you use UIModalTransitionStyleCoverVertical).

The layer's speed is not an absolute value but a function of that layer's parent time space (unless the layer is in the root of the layer hierarchy of course). For example, when you set a layer's speed to 2, its animations will run twice as fast in comparison to that layer parent's animations.

Yet another option is to use view controller containment. (iOS 5 and later only)

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

You have full control over the animation with UIViewController's transitionFromViewController:toViewController:duration:options:animations:completion:.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!