在Swift中创建滑动序列 [英] Creating a sliding segue in Swift
问题描述
我正在尝试在两个滑动到下一个View Controller的View Controller之间创建序列/过渡。我所说的滑动是指它的移动幅度仅为平移手势的平移幅度(类似于Snapchat)。如果您可以为我提供帮助,或者只是为我指明正确的方向,那就太好了。
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.
推荐答案
可以达到这种效果使用自定义互动过渡,这是iOS7中引入的。以下是一些要检查的教程:
That effect is achieved using custom interactive transitions, which were introduced in iOS7. Here are a few tutorials to check out:
- 请参见使用视图控制器的自定义转换。 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 /
- 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/
当我实现此功能时,我发现可重用性,最好是有一个 UIPercentDrivenInteractiveTransition
(我们称为 TransitionManager
)的子类来实现协议 UIViewControllerTransitioningDelegate
, UINavigationControllerDelegate
和 UIViewControllerAnimatedTransitioning
。
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
.
-然后,如果您需要以自定义过渡方式模态显示 UIViewController
:在 prepareForSegue
中设置:
- Then, if you need to present a UIViewController
modally with your custom transition: in prepareForSegue
set:
destinationViewController.modalPresentationStyle = .Custom
destinationViewController.transitioningDelegate = TransitionManager()
-使用 UINavigationController
会更容易,您所需要做的只是设置 UINavigationController
的委托
到您的 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.
这篇关于在Swift中创建滑动序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!