[英]How do I segue to a new view controller after a short timeout?
I want to show the user a title screen of the app name firstly and then, after about 2 seconds, the view should proceed to a new view controller. 我想先向用户显示应用程序名称的标题屏幕,然后在大约2秒钟后,视图应进入新的视图控制器。
So far, I have a segue with an identifier. 到目前为止,我有一个带有标识符的segue。 I see a lot of tutorials use IBAction
s/ IBOutlet
s but I'm not sure if I would use one here since there's no single item that would trigger the segue aside from the timeout. 我看到很多教程都使用IBAction
s / IBOutlet
但是我不确定在这里是否要使用IBAction
,因为没有一个项目会在超时之外触发触发segue。
Just use DispatchQueue.main.asyncAfter(deadline:)
in viewDidLoad
. 只需在viewDidLoad
使用DispatchQueue.main.asyncAfter(deadline:)
。 This code triggers the segue with the given identifier after a 2 seconds delay: 这段代码会在2秒钟的延迟后使用给定的标识符触发segue:
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.performSegue(withIdentifier: "your segue's identifier", sender: self)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.