iOS7 View Controller Transitioning API’s
Throughout Completely there are a number of different transitions, some are standard, like the navigation controller push, others are custom. For example, I wanted the navigation controller push animation when presenting the search results however the ‘Search’ screen is not inside a navigation controller (I didn’t want the navigation bar or the hassle of showing/hiding it during the new interactive pop transition) and so the results are presented modally. For this I tried a few options, firstly I tried a custom segue by subclassing UIStoryBoardSegue, implementing the animation of views frame position and setting this class as the class of the segue in the storyboard. This turned out to be very slightly ‘stuttery’ and not the smooth transition I wanted.
iOS7 view controller transitioning API’s to the rescue. The great thing about these API’s is that the presenting view controller and it’s view that gets covered by the presented view, remains ‘as is’ and visible, meaning you can present modal view controllers that only take up part of the screen and the view behind remains visible. Normally the view behind would go black as it wouldn’t normally be visible. I’d imagine Apple have used these API’s or similar in their iRadio app that presents blurred view controllers through which you can see the view behind.
So how do you use these APIs? I watched the Apple presentation that introduced these new API’s at WWDC 2013, which allowed for a great conceptual understanding, but not so much a practical one. Unlike the other presentations, Apple failed to release the sample code for this presentation however an iOS developer, Jesse Wolff has kindly recreated the app demoed and has posted the code on GitHub.
SOLPresentingFun - https://github.com/soleares/SOLPresentingFun
As always, there’s no better way to learn than playing about with the code itself, before long I’d implemented a number of different transitions in Completely, including animating dismissal of view controllers. In short, it’s a matter of creating an ‘Animator’ class that handles grabbing the ‘to’ and ‘from’ view controllers from the ‘animated transitioning context’ along with implementing the <UIViewControllerAnimatedTransitioningDelegate> methods in the presenting view controller where you create and return your ‘Animator’.
Any questions feel free to drop me an email, in the mean time, check out Jesse’s code for a complete overview of whats possible.