Search code examples
swiftseguecatransition

Creating a sliding segue in Swift


I am trying to create a segue/transition between two View Controllers that "slides" to the next View Controller. What I mean by "slide" is that it only moves as much as the translation of a pan gesture(similar to Snapchat). If you could help me with this or just point me in the right direction, that would be great.


Solution

  • That effect is achieved using custom interactive transitions, which were introduced in iOS7. Here are a few tutorials to check out:


    When I was implementing this I found that, for reusability, it was best to have one subclass of UIPercentDrivenInteractiveTransition (which we'll call TransitionManager) that implemented the protocols UIViewControllerTransitioningDelegate, UINavigationControllerDelegate and UIViewControllerAnimatedTransitioning.

    - Then, if you need to present a UIViewController modally with your custom transition: in prepareForSegue set:

    destinationViewController.modalPresentationStyle = .Custom
    destinationViewController.transitioningDelegate  = TransitionManager()
    

    - If you're using a UINavigationController it's even easier, all you need to do it set the UINavigationController's delegate to your TransitionManager.

    Hopefully that should start to make some sense once you've gone through the tutorials.