How can I get custom transitions (iOS7) when pushing a view controller onto UINavigationController
? I tried setting the TransitioningDelegate
both in the UINavigationController
and also on the controller I'm pushing
The methods never get called.
All examples I find use custom transitions when presenting modally.
You can look at my demo project which demonstrates using custom transitions in
UINavigationController
. Look at https://github.com/Vaberer/BlurTransition.objc.io's post on view controller transitions are specifically for pushing and popping view controllers. http://objc.io/issue-5/view-controller-transitions.html
I've done this animation (http://i.imgur.com/1qEyMu3.gif) solely based on the objc.io post.
In short you have to have a class(es) implementing
UINavigationControllerDelegate
, andUIViewControllerAnimatedTransitioning
with the required methods for returning the correct animator, and performing the animations.@rounak has the right idea, but sometimes it helps to have code ready without having to download from github.
Here are the steps that I took:
Make your FromViewController.m conform to
UINavigationControllerDelegate
. Other sample code out there tells you to conform toUIViewControllerTransitioningDelegate
, but that's only if you're presenting the ToViewController.@interface ViewController : UIViewController
Return your custom transition animator object in the delegate callback method in FromViewController:
Create your custom animator class and paste these sample methods:
Essentially, the animator is the object doing the heavy lifting. Of course, you can make your UINavigationControllerDelegate be a separate object, but that depends on how your architect your app.
EDIT: Just realised this might not answer your question. But it is an alternative.
If you're using a storyboard you can do a custom transition by creating a custom segue. In the attributes inspector change the segue class name to your custom transition class e.g.
MySegue
. Then create theMySegue
class and implement the-(void)perform
method to perform your transition.