简体   繁体   中英

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. 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). 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 {

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)

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!

You are calling sleep on the main thread.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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