What is the proper way to change the UINavigationController transition effect
- by Felipe Sabino
I have seen lots of people asking on how to push/pop UINavigationControllers using other animations besides the default one, like flip or curl.
The problem is that either the question/answer was relative old, which means the have some things like [UIView beginAnimations:] (example here) or they use two very different approaches.
The first is to use UIView's transitionFromView:toView:duration:options:completion: selector before pushing the controller (with the animation flag set to NO), like the following:
UIViewController *ctrl = [[UIViewController alloc] init];
[UIView transitionFromView:self.view
toView:ctrl.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:nil];
[self.navigationController pushViewController:ctrl animated:NO];
Another one is to use CoreAnimation explicitly with a CATransaction like the following:
// remember you will have to have the QuartzCore framework added to your project for this approach and also add <QuartzCore/QuartzCore.h> to the class this code is used
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.duration = 1.0f;
transition.type = @"flip";
transition.subtype = @"fromTop";
[self.navigationController.view.layer removeAllAnimations];
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIViewController *ctrl = [[UIViewController alloc] init];
[self.navigationController pushViewController:ctrl animated:NO];
There are pros and cons for both approaches.
The first approach gives me a much cleaner code but restricts me from using animations like "suckEffect", "cube" and others.
The second approach feels wrong just by looking at it. It starts by using undocumented transitions types (i.e. not present in the Common transition types documentation from CATransition Class Reference) which might get your app rejected from App Store (I mean might as I could not found any reference of apps being rejected because it was using this transactions, which I would also appreciate any clarification on this matter), but it gives you much more flexibility on your animations, as I can use other animation types such as "cameraIris", "rippleEffect" and so on.
Regarding all that, do I really need to appeal for QuartzCore and CoreAnimation whenever I need a fancier UINavigationController transition? Is there any other way to accomplish the same effect using only UIKit?
If not, will the use of string values like "flip" and "cube" instead of the pre-defined constants (kCATransitionFade, kCATransitionMoveIn, etc...) be an issue regarding my app approval in the App Store?
Also, are there other pros and cons regarding both approaches that could help me deciding whether to choose each one of them?