Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How long is the animation of the transition between views on a UINavigationController?

Ideally, there would be some kind of constant containing this value.

I'm implementing code that has it's own transition animations, and I'd like those to have the same length as the platform transition animations.

like image 386
morais Avatar asked Sep 30 '11 10:09

morais


People also ask

What is iOS animation duration?

On iOS 8 the animation duration appears to be 0.2 seconds. (There is now a constant you can refer to: UINavigationControllerHideShowBarDuration .)

How do you do transition animation?

In the Thumbnail Pane, select the slide where you want to apply or change a transition. On the Transitions tab, find the effect that you want in the Transition gallery. Select Effect Options to specify how the transition occurs. If you want all slides in the presentation to transition the same way, select Apply To All.


2 Answers

In iOS 7 and later you can have exact value by setting the UINavigationController delegate and using the method:

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {
    NSTimeInterval duration = [viewController.transitionCoordinator transitionDuration];
}  

This is future proof method if the defult duration will ever change. At the moment it's value is 0.35 second.

like image 170
Tomasz Bąk Avatar answered Sep 24 '22 16:09

Tomasz Bąk


There's no constant containing this value. However, using the following UINavigationControllerDelegate methods:

- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    startTime = [[NSDate date] retain];
}

- (void) navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    NSLog(@"Duration %f", [[NSDate date] timeIntervalSinceDate: startTime]);
}

... I can see that the duration is approx 0.35 seconds

Interestingly, different parts of the views take different times to transition into place. See this great blog post for more details:

http://www.iclarified.com/12396/a-closer-look-at-iphone-transition-animations

like image 21
Ashley Mills Avatar answered Sep 21 '22 16:09

Ashley Mills