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

2

20

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.

Inversion answered 30/9, 2011 at 10:27 Comment(0)
M
23

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

Morville answered 30/9, 2011 at 10:54 Comment(4)
On iOS 8 the animation duration appears to be 0.2 seconds. (There is now a constant you can refer to:UINavigationControllerHideShowBarDuration.)Prestonprestress
This comment should be an answer, it's helped me many many timesPithy
This constant only applies to the animation of navigation BARS, not the viewController views themselves.Unprincipled
The timing of UINavigationController.hideShowBarDuration appears to be faster than the push/pop animation.Kosse
L
27

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.

Lelia answered 27/2, 2015 at 14:16 Comment(0)
M
23

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

Morville answered 30/9, 2011 at 10:54 Comment(4)
On iOS 8 the animation duration appears to be 0.2 seconds. (There is now a constant you can refer to:UINavigationControllerHideShowBarDuration.)Prestonprestress
This comment should be an answer, it's helped me many many timesPithy
This constant only applies to the animation of navigation BARS, not the viewController views themselves.Unprincipled
The timing of UINavigationController.hideShowBarDuration appears to be faster than the push/pop animation.Kosse

© 2022 - 2024 — McMap. All rights reserved.