如果您的UI在Storyboard中布局,您可以在第一个ViewController的viewDidLoad中设置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中设置segue的方法:
>控制从第一个ViewController的File’s Owner图标拖动到第二个ViewController.
>从弹出窗口中选择“模态”.
>单击视图控制器之间出现的segue箭头.在segue的Attributes Inspector中…>给你的segue一个标识符.>如果您不想看到屏幕滑入,请关闭动画.