Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I increase the animation speed of presentModalViewController?

I'm writing a drawing application that shows a tools view controller when the user clicks an item in a toolbar. However, several of my beta testers have reported that the tools palate opens too slowly. I'm using the standard presentModalViewController:animated: call to display the tools, and I've tried wrapping it in a code block like this to speed it up:

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

Unfortunately, that doesn't work. If you say animated:NO it works better, but the underlying drawing canvas view is removed immediately (since the controller thinks it is no longer visible), and so the animation occurs over a white background.

Has anyone done this before that would be willing to offer some advice? I'd appreciate it!

like image 828
Ben Gotow Avatar asked Dec 09 '22 20:12

Ben Gotow


2 Answers

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:.

like image 157
AngraX Avatar answered Jan 11 '23 23:01

AngraX


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.

like image 20
zpasternack Avatar answered Jan 11 '23 22:01

zpasternack