簡體   English   中英

Swift 4.0延遲啟動屏幕導致項目消失

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

我正在使用Swift 4.0創建一個應用,並且試圖延遲啟動屏幕。 初始屏幕將睡眠2秒鍾,然后“ FusionPointInc應用程序”標簽將消失,並且屏幕將停留在紅色幕布背景圖像(第二個圖像)上。 它將停留在該位置,並且不會顯示第二個屏幕(“劇院舞台整個歷史記錄”屏幕)

這是我的初始屏幕代碼:

override func viewDidLoad() {
    super.viewDidLoad()

    sleep(2)

    showNavController()
}

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

ThreeImages ImageThatHasNoLabel

初始屏幕的更多代碼(將過渡到第二個屏幕):

`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.
}
*/

}

該屏幕將打開,並在提示您進行篩選時,該屏幕僅顯示背景(第二張圖片)。

中間的屏幕代碼位於ViewController.swift文件中,並且其中沒有實際的代碼(只有預先格式化的基本代碼)

我在刪除初始屏幕時進行了測試,該應用程序將正常加載。 但是,我希望延遲初始屏幕,以便可以看到“ FusionPointInc應用程序”!

您正在主線程上調用sleep。

相反,您應該這樣做:

override func viewDidLoad() {
    super.viewDidLoad()

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

這將在兩秒鍾后無問題地調用showNavController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM