Custom Interactive UI-Direction-Responsive Push-Pop Animation

iOS 7 gives us an amazing out-of-the-box interactive pop animation. It looks and feels nice, but this is only the tip of the iceberg, and it still doesn’t gives us a custom animation. For that we are going to use the new API and to create a new push-pop animation, that is both custom, interactive, AND changes it’s way depending on the UI (RTL or LTR).
We start with a VC that will push a second VC, this clean version of the projection does nothing but push-pop.
InteractiveNav v1 (Clean Xcode Project)
1.3mb
On viewDidAppear: (Override if needed…) of AOMainViewController we will set self as delegate:

and of course declare ourselves as delegate in the .h:

Now we are going to implement one of the delegate methods:

This method suppose to return an object that is a delegate of UIViewControllerAnimatedTransitioning (If this is your first time dealing with the new custom animation API than – yes – LOTS of delegates around here…).
We will create an object that will be our delegate, let’s call it AOViewControllerTransition.
We need to declare delegate of UIViewControllerAnimatedTransitioning in it’s .h and import it to AOMainViewController.
Now all we have left to do is declare some BOOLs properties to know which animation to do and our method will be warnings-free.

The last thing we need to do is to implement 2 (non-optional) methods in AOViewControllerTransition’s .m:

If we run this now we have a nice push animation that is not only custom, but also changes direction when we switch between RTL and LTR UI!
But few things are missing – first of all – we don’t have the custom animation also when popping back, second – we now have ruined the interactive transition for popping.
Let’s first fix the pop: In AOSecondViewController use our AOViewControllerTransition the same way to get the custom animation:

    • Set self as delegate for UINavigationControllerDelegate in the .h.
    • Call #import "AOViewControllerTransition.h" in the .m.
    • Implement navigationController:animationControllerForOperation:fromViewController:toViewController: exactly the same way (Making a specific delegate object is the way to go here, i’m just being lazy).
    • Tell AOSecondViewController about the UI direction by adding a property and setting it in the push method:
    • Replace the line that sets the transition direction:

That’s it! We now have a transition animation that is both custom for push and pop, and also goes with the UI direction!

About interactive transition – We have few options to implement this, and we will go with a simple one, using the new UIScreenEdgePanGestureRecognizer that came with iOS7. We will add it to viewDidLoad in AOSecondViewController:

Than we implement handlePopRecognizer::

If we will run now, our GestureRecognizer will call and make the animation, but since we have yet to connect the animation our interactivePopTransition it won’t be interactive. What we need to do is simply add this method:

And we are done!
InteractiveNav v2 (Final Solution Xcode Project)

*To create the basic interactive transition I have used the tutorial of another great blog, and I never kept the link – If you have any idea which one it was please tell me so I can add a link to his post.