Search code examples
iosxcodeuiviewcontrollercustom-transition

Can I control the transition (ie through user swiping) between two view controllers?


I wish to have one view controller slide off the screen as the user drags it, with the user able to drag their fingers back and forth to control the transition.

I know that custom transitions are possible, and was wondering if this was possible?


Solution

  • Yes, use a gesture recognizer that initiates custom transition and and also updates interaction controller (e.g. a UIPercentDrivenInteractiveTransition). The specifics depend upon whether the transition is modal or navigation controller.

    • For presentViewController, your destination view controller needs to specify a custom transition type and specify a transitioningDelegate. This UIViewControllerTransitioningDelegate can specify both the animation controller and the interaction controller.

    • For navigation controllers, you would specify the delegate of the navigation controller, and there are UINavigationControllerDelegate methods you can implement to specify the animation and interaction controllers.

    See WWDC 2013 video Custom Transitions Using View Controllers which discusses this in great detail.