Creating a sliding segue in Swift

前端 未结 1 757
滥情空心
滥情空心 2021-02-11 07:38

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

1条回答
  •  独厮守ぢ
    2021-02-11 08:12

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

    • See Custom Transitions Using View Controllers. https://developer.apple.com/videos/wwdc/2013/
    • http://www.thinkandbuild.it/ios7-custom-transitions/
    • http://objectivetoast.com/2014/04/14/interactive-transitions/
    • http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
    • This one gives many examples of the effects that can be achieved. http://www.appcoda.com/custom-view-controller-transitions-tutorial/

    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.

    0 讨论(0)
提交回复
热议问题