Creating a sliding segue in Swift

北城以北 提交于 2019-12-09 07:18:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/29785130/creating-a-sliding-segue-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!