3

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?

Community
  • 1
  • 1
Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112

1 Answers1

1

With regards to the AppStore approval, I don't think its a deal-breaker based on what animation libraries you use. You can use which ever you feel is convenient for you, and can use them together as well. From a personal standpoint, I would say the CoreAnimation & QuartzCore are pretty awesome when you are trying to add animation to a particular event. Its great because of the level of detail you can add to individual components.

But those are not your only options. You should have a look at COCOS2D libraries for animation. They are really awesome and extremely simple to use. For example if using CoreAnimation takes you 30 lines of code, you can use COCOS2D and set it up with 3-5 lines of code. Also, you can integrate Physics with each component when you use the COCOS2D framework (chipmunk).

Legolas
  • 12,145
  • 12
  • 79
  • 132
  • 1
    I have tried cocos2d a while ago, waaay before the 1.0 release and as far as I remember I could not use their animations together with UIKit, I mean, I had to use their CCxxx classes like CCSprites or something like this... so it is possible to use their animation framework while pushing a `UIViewControlller` in my `UINavigationController`? That would be awesome! If so can you provide some code of how to accomplish that? – Felipe Sabino Apr 11 '12 at 21:34
  • 1
    I don't think this is possible, Cocos2D uses OpenGL and manages it's own views etc. – Maciej Swic Nov 28 '12 at 15:27