我正在尝试在两个“滑动”到下一个 View Controller 的 View Controller 之间创建一个 segue/transition。我所说的“滑动”是指它的移动幅度与平移手势的平移量一样多(类似于 Snapchat)。如果您能帮我解决这个问题,或者为我指明正确的方向,那就太好了。
最佳答案
该效果是使用 iOS7 中引入的自定义交互过渡实现的。以下是一些可供查看的教程:
- 请参阅使用 View Controller 自定义转换。 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/
- 本文给出了许多可以实现的效果示例。 http://www.appcoda.com/custom-view-controller-transitions-tutorial/
当我实现它时,我发现,为了可重用性,最好有一个 UIPercentDrivenInteractiveTransition
的子类(我们称之为 TransitionManager
)来实现协议(protocol)UIViewControllerTransitioningDelegate
、UINavigationControllerDelegate
和 UIViewControllerAnimatedTransitioning
。
- 然后,如果您需要使用自定义转换以模态方式呈现 UIViewController
:在 prepareForSegue
中设置:
destinationViewController.modalPresentationStyle = .Custom
destinationViewController.transitioningDelegate = TransitionManager()
- 如果您使用的是 UINavigationController
,那就更简单了,您只需设置 UINavigationController
的 将
委托(delegate)给您的 TransitionManager
。
希望您在完成教程后开始明白这一点。
关于swift - 在 Swift 中创建滑动转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785130/