Storyboard Custom Segue For Custom PushViewController Animation

While there are a lot of google hits when searching for custom pushViewController Animation, I found nothing regarding use of a Custom Segue to make it reusable and I also found a lot of misinformation like “it can’t be done with the default UINavigationController.” It can.

From your Button, View, Gesture Recognizer or whatever, instead of dragging from Push, drag from Custom.

Then select the Segue that is created and type in a class name the custom Segue.

Now we can create the FromTopReplaceSegue class. Use Add File or however you like to create new classes in XCode.

In this CustomSegue not only are we doing custom animation from Top to Bottom (just like the default push navigation of Right to Left) but instead of pushing, we are replacing the top view controller.

In my current project I have a nearly identical FromButtomReplaceSegue that does the replace but animates from Button. I hope for a library of these with varying animation transitions and Push/Replace variants of each. Then anytime you want to use a different animation you can simply use a Custom Segue instead of writing a bunch of code in ViewDidLoad or wherever. Hurray Storyboard!

how can you control the animation so instead of happening from top to bottom it happens from left to right or vice versa – may be i am missing something but i couldn’t see this part in the code snippet you provided

Yes, it is all there. It is called implicit animation. When you turn implicit animation on, by sending UIView class the beginAnimations message, setting the rectangle will animate the change of these coordinates automatically. There is default time span for the animation which I do not change. If you read about implicit animation it will become more clear.

This is very good. I like how at the end you also push the viewController of the destination view after the animation. Just one question though- why in your animationDone() method are you doing : [nav popViewControllerAnimated:No]. Popping the current viewController will not allow you to go back to it from the viewController that you are going to (in other words *dst). So in my dst view if I have a “back” button it will not go back to the correct view because you would have popped it off. It might actually crash the app if there are no more viewControllers left in the naviagtionArray after doing that pop. Please advise if I am missing something. Great answer, very useful. Thanks from Australia