I am trying to create a custom container controller within my iPhone app. I would like this container to implement custom transitions, just like the default behavior of TabBarControllers and NavigationControllers within iOS 7. I have successfully been able to add custom animations to my transitions, but am having trouble adding the interactive logic.
As part of the transition process, I must create a TransitionContext. This is normally created by the system, but since I am using a custom container controller I have created my own class that conforms to the UIViewControllerContextTransitioningProtocol. When the gesture recognizer tied to the transition is triggered, I attempt to begin the transition by calling:
[self.horizontalSwipeInteractionController startInteractiveTransition:transitionContext];
where self.horizontalSwipeInteractionController inherits from UIPercentDriveInteractiveTranstion. Unfortunately, I get the following error at this point:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PrivateTransitionContext _animator]: unrecognized selector sent to instance 0x14654a80
I don't understand what to do now. The documentation gives no examples on how to implement custom transitions with custom container controllers.
Unfortunately, UIPercentDriveInteractiveTranstion
uses private APIs.
Alek Åström writes about this on his iOS Nomad blog where he walks through creating an interactive custom container controller (emphasis added):
... we can see that UIPercentDrivenInteractiveTransition looks for the animator in our context, calling an undocumented method. Conveniently enough, all Apple-made transition contexts implement this method and that's how the percent driven transition can fire the animation. Unfortunately, that means we cannot use the class for our own custom container view controllers.
He recommends using AWPercentDrivenInteractiveTransition
as a drop in replacement.