自定义幻灯片 Segue - Xcode 8.0 Swift 3.0
Posted
技术标签:
【中文标题】自定义幻灯片 Segue - Xcode 8.0 Swift 3.0【英文标题】:Custom Slide Segue - Xcode 8.0 Swift 3.0 【发布时间】:2016-10-24 10:44:42 【问题描述】:创建自定义 segue 的最佳方法是什么,让我按下一个按钮,然后视图控制器就会滑动。我创建了一个从左到右的 segue,但我想让它走另一条路。我看过一些Youtube 和this question 的视频,但它们并没有告诉我我想要什么。
我的代码:
import UIKit
class SegueFromLeft: UIStoryboardSegue
override func perform()
let src = self.sourceViewController
let dst = self.destinationViewController
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransformMakeTranslation(-src.view.frame.size.width, 0)
UIView.animateWithDuration(0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations:
dst.view.transform = CGAffineTransformMakeTranslation(0, 0)
,
completion: finished in
src.presentViewController(dst, animated: false, completion: nil)
)
基本上,我想创建一个从右到左的转场。
谢谢
我正在使用 Xcode 8.0 和 Swift 3.0
【问题讨论】:
你成功了吗?你试过我的答案了吗? 【参考方案1】:试试这个:
class SegueFromLeft: UIStoryboardSegue
override func perform()
let src=sourceViewController
let dst=destinationViewController
let slide_view=destinationViewController.view
src.view.addSubview(slide_view)
slide_view.transform=CGAffineTransform.init(translationX: src.view.frame.size.width, 0)
UIView.animateWithDuration(0.25,
delay: 0.0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations:
slide_view.transform=CGAffineTransform.identity
, completion: finished in
src.present(dst, animated: false, completion: nil)
slide_view.removeFromSuperview()
)
【讨论】:
【参考方案2】:Swift 3.1:
class ProceedToAppStoryboardSegue: UIStoryboardSegue
override func perform()
let slideView = destination.view
source.view.addSubview(slideView!)
slideView?.transform = CGAffineTransform(translationX: source.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations:
slideView?.transform = CGAffineTransform.identity
, completion: finished in
self.source.present(self.destination, animated: false, completion: nil)
slideView?.removeFromSuperview()
)
【讨论】:
以上是关于自定义幻灯片 Segue - Xcode 8.0 Swift 3.0的主要内容,如果未能解决你的问题,请参考以下文章