swift - 在 Swift 中创建滑动转场

标签 swift segue catransition

我正在尝试在两个“滑动”到下一个 View Controller 的 View Controller 之间创建一个 segue/transition。我所说的“滑动”是指它的移动幅度与平移手势的平移量一样多(类似于 Snapchat)。如果您能帮我解决这个问题,或者为我指明正确的方向,那就太好了。

最佳答案

该效果是使用 iOS7 中引入的自定义交互过渡实现的。以下是一些可供查看的教程:


当我实现它时,我发现,为了可重用性,最好有一个 UIPercentDrivenInteractiveTransition 的子类(我们称之为 TransitionManager)来实现协议(protocol)UIViewControllerTransitioningDelegateUINavigationControllerDelegateUIViewControllerAnimatedTransitioning

- 然后,如果您需要使用自定义转换以模态方式呈现 UIViewController:在 prepareForSegue 中设置:

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

- 如果您使用的是 UINavigationController,那就更简单了,您只需设置 UINavigationController 委托(delegate)给您的 TransitionManager

希望您在完成教程后开始明白这一点。

关于swift - 在 Swift 中创建滑动转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785130/

相关文章:

ios - 在构建 iOS 应用程序时,在范围错误中获取找不到类型 'UIHostingController'

annotations - 在没有 segue anchor 的 mapkit 注释上定位 segue popover

ios - 带有平移手势的 CATransition Cube

iphone - 使用 CAAnimation 实现 CATransition 推送

ios - 在下次运行之前以后台模式关闭应用程序

linux - 涉及 Swift 3.0.2 的重定向 URL 的问题

swift - 当抛出一个可选的-nil错误时,如何获得默认的错误字符串?

ios - Xcode 6 storyboard unwin segue Action 未定义

ios - 在 ibaction 后触发 segue

ios - UILabel 的图层在动画时不更新颜色