ios - 在 Swift 中设置自定义 segue 方式(从顶部到按钮的方向)

标签 ios xcode swift storyboard segue

我想在 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中使用您的新自定义转场:

custom segue

关于ios - 在 Swift 中设置自定义 segue 方式(从顶部到按钮的方向),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37899312/

相关文章:

iphone - 分组的 UITableViews 和图像 mask

ios - 如何在 Swift 中创建弹出 View

swift - tableView.reloadData() 不工作,可能没有在主线程上调用

ios - Xcode 13 - "Button"标题没有消失

ios - Apple 开发者证书 - 备份什么

ios - Firebase observeSingleEvent 保留在内存中

ios - 如何更改 UITabBarItem 操作?

ios - SDWebImage 检查图像是否使用 Swift 缓存 : Ambiguous Reference

swift - 在 UIViewcontroller 中有一个自定义的 UIView

ios - 如何使用 Xcode 调试器打印出属性的内容?