簡體   English   中英

如何在 iOS Swift 的啟動(啟動)屏幕上顯示警報 5

[英]How to show an alert at Splash (Launch) Screen in iOS Swift 5

我想使用 Swift 5 在 iOS 的啟動屏幕上顯示警報。基本上,我正在檢查是否滿足某個條件,如果不滿足,則使用簡單的“OK”或“Dismiss”顯示警報。

這是代碼,它不起作用:

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

    if conditionMet
            {
                print("Condition met!")
            }
            else
            {
                
                let storyboard : UIStoryboard = UIStoryboard(name: "Launch Screen", bundle: nil)
                let launchScreenCtrler = storyboard.instantiateViewController(identifier: "LAUNCH_SCREEN")
                let alertViewFrame = CGRect(x: 100, y: 300, width: 120, height: 80)
                let newView : UIView = UIView(frame: alertViewFrame)
                launchScreenCtrler.view.addSubview(newView)
                launchScreenCtrler.view.bringSubviewToFront(newView)
  
                alert.show(launchScreenCtrler, sender: newView)
     
            }
}

關於我缺少什么的任何想法?

謝謝,

啟動屏幕(您可能在LaunchScreen.storyboard中設置的那個)不是“可交互的”:您可以使用界面構建器中的自動布局來設計其 UI,僅此而已。

應用程序啟動后根據某些條件顯示警報的最佳位置是從當前 window 的根視圖 controller 中,也就是將被實例化的第一個視圖 controller。

暫無
暫無

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

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