OGeek|极客世界-中国程序员成长平台

标题: swift - 如何使用 Swift 在 Xcode 6 中执行自动转场? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:24
标题: swift - 如何使用 Swift 在 Xcode 6 中执行自动转场?

我希望在应用加载一段时间后从主视图 Controller 自动切换到第二个 View Controller 。

我该怎么做?

我需要以编程方式进行吗?



Best Answer-推荐答案


如果你的 UI 布局在 Storyboard 中,你可以在你的第一个 ViewControllerviewDidLoad 中设置一个 NSTimer 然后调用 >performSegueWIthIdentifier 当定时器触发时:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let timer = Timer.scheduledTimer(interval: 8.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)
    }

    @objc func timeToMoveOn() {
        self.performSegue(withIdentifier: "goToMainUI", sender: self)
    }

这是在 Storyboard 中设置转场的方法:

  1. 控制从第一个 ViewController 的 File's Owner 图标拖动到第二个 ViewController
  2. 从弹出窗口中选择“模态”。

Seting up the segue


  1. 单击出现在 View Controller 之间的segue 箭头。在 Attributes Inspector 中为 segue...
  2. 给你的 segue 一个标识符。
  3. 如果您不想看到屏幕滑入,请关闭 动画

enter image description here

关于swift - 如何使用 Swift 在 Xcode 6 中执行自动转场?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51547348/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4