简体   繁体   English

如何在 iOS Swift 的启动(启动)屏幕上显示警报 5

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

I want to show an alert on the Launch screen in iOS using Swift 5. Basically, I am checking if a certain condition is met, and if it isn't, then show the alert with a simple "OK" or "Dismiss".我想使用 Swift 5 在 iOS 的启动屏幕上显示警报。基本上,我正在检查是否满足某个条件,如果不满足,则使用简单的“OK”或“Dismiss”显示警报。

Here is the code, which is not working:这是代码,它不起作用:

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)
     
            }
}

Any ideas as to what am I missing?关于我缺少什么的任何想法?

Thanks,谢谢,

The launch screen (the one you are presumably setting up in LaunchScreen.storyboard ) is not "interactable": you can design its UI using auto layout in interface builder, but that's it.启动屏幕(您可能在LaunchScreen.storyboard中设置的那个)不是“可交互的”:您可以使用界面构建器中的自动布局来设计其 UI,仅此而已。

The best place to show an alert based on some condition as soon as the app launches is from the root view controller of your current window, aka the first view controller that will be instantiated.应用程序启动后根据某些条件显示警报的最佳位置是从当前 window 的根视图 controller 中,也就是将被实例化的第一个视图 controller。

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

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