简体   繁体   English

Swift 4.0延迟启动屏幕导致项目消失

[英]Swift 4.0 Delayed Launch Screen Causes Items to disappear

I am creating an app with Swift 4.0 and I am trying to delay the launch screen. 我正在使用Swift 4.0创建一个应用,并且试图延迟启动屏幕。 The initial screen will sleep for 2 seconds, then the "a FusionPointInc application" label will disappear and the screen will stay at the red curtain background image (the second image). 初始屏幕将睡眠2秒钟,然后“ FusionPointInc应用程序”标签将消失,并且屏幕将停留在红色幕布背景图像(第二个图像)上。 It will stay there and won't show the second screen (the Theater Stages Throughout History screen) 它将停留在该位置,并且不会显示第二个屏幕(“剧院舞台整个历史记录”屏幕)

Here is my code for the initial screen: 这是我的初始屏幕代码:

override func viewDidLoad() {
    super.viewDidLoad()

    sleep(2)

    showNavController()
}

func showNavController() {
    performSegue(withIdentifier: "showMainView", sender: self)
}

ThreeImages ImageThatHasNoLabel

More code for the initial screen (will transition to the second screen): 初始屏幕的更多代码(将过渡到第二个屏幕):

`class showMainView: UIViewController { `class showMainView:UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    //performSegue(withIdentifier: "showSegue", sender: self)
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

} }

This screen will open and when prompted to segue, the screen will only show the background (the second picture). 该屏幕将打开,并在提示您进行筛选时,该屏幕仅显示背景(第二张图片)。

The middle screen code is in the ViewController.swift file and it has no actual code in it (just the pre-formatted base code) 中间的屏幕代码位于ViewController.swift文件中,并且其中没有实际的代码(只有预先格式化的基本代码)

I tested when I delete the initial screen, the app will load up fine. 我在删除初始屏幕时进行了测试,该应用程序将正常加载。 But, I wanted the initial screen to be delayed so "a FusionPointInc application" can be seen! 但是,我希望延迟初始屏幕,以便可以看到“ FusionPointInc应用程序”!

You are calling sleep on the main thread. 您正在主线程上调用sleep。

Instead, you should be doing something like this: 相反,您应该这样做:

override func viewDidLoad() {
    super.viewDidLoad()

    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
       self.showNavController()
    }
}

This will call showNavController after two seconds without issues. 这将在两秒钟后无问题地调用showNavController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM