With the UIView
animation API and view controller containment the current Cocoa Touch stack is very well suited for automatic transitions between view controllers.
What I find hard to write are interactive transitions between view controllers. As an example, when I just want to replace one view with another using a push animation, I can use UINavigationController
or use the containment API and write the transition myself. But it’s quite common that I want the transition to be interactive, touch-controlled: user starts dragging the current view, the incoming view appears from the side and the transition is controlled by the panning touch gesture. The user can just pan a little to “peek” at the incoming view and then pan back, keeping the current view visible. If the gesture ends below a certain treshold, the transition is cancelled, otherwise it’s completed.
(In case this is not clear enough, I’m talking about something like the page turn in iBooks, but between different view controllers, and generalized to any such interactive transition.)
I know how to write such a transition, but the current view controller has to know too much about the transition – it takes up too much of its code. And that’s not even mentioning that there can easily be two different interactive transitions possible, in which case the controllers in question are full of the transition code, tightly coupled to it.
Is there a pattern to abstract, generalize the interactive transition code and move it into a separate class or code lump? Maybe a library, even?