我想在 Storyboard 中的两个场景之间建立一个 segue,其行为与“Apple Keynote”效果完全相同(从上到下方向)。现在我知道有一种称为模态转场的转场,但它在自下而上的方向上起作用。
请帮帮我!
我做了一个视频,我想要什么样的segue,请看一下! https://www.dropbox.com/s/zqyxrm638ellfbx/whatiwant.mov?dl=0
最佳答案
您可以像这样实现自定义 UIStoryboardSegue
:
class TopDownSegue: UIStoryboardSegue {
let duration: NSTimeInterval = 1
let delay: NSTimeInterval = 0
let animationOptions: UIViewAnimationOptions = [.CurveEaseInOut]
override func perform() {
// get views
let sourceView = sourceViewController.view
let destinationView = destinationViewController.view
// get screen height
let screenHeight = UIScreen.mainScreen().bounds.size.height
destinationView.transform = CGAffineTransformMakeTranslation(0, -screenHeight)
// add destination view to view hierarchy
UIApplication.sharedApplication().keyWindow?.insertSubview(destinationView, aboveSubview: sourceView)
// animate
UIView.animateWithDuration(duration, delay: delay, options: animationOptions, animations: {
destinationView.transform = CGAffineTransformIdentity
}) { (_) in
self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil)
}
}
}
并在 Storyboard中使用您的新自定义转场:
关于ios - 在 Swift 中设置自定义 segue 方式(从顶部到按钮的方向),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37899312/