UIWindow not showing over content in iOS 13

后端 未结 12 1690
野的像风
野的像风 2020-12-07 17:41

I am upgrading my app to use the new UIScene patterns as defined in iOS 13, however a critical part of the app has stopped working. I have been using a UI

12条回答
  •  余生分开走
    2020-12-07 18:36

    iOS 13 broke my helper functions for managing alerts.

    Because there may be cases where you need multiple alerts to be displayed at the same time (the most recent above the older) for example in case you're displaying a yes or no alert and in the meanwhile your webservice returns with a error you display via an alert (it's a limit case but it can happen),

    my solution is to extend the UIAlertController like this, and let it have its own alertWindow to be presented from.

    The pro is that when you dismiss the alert the window is automatically dismissed because there is any strong reference left, so no further mods to be implemented.

    Disclaimer : I just implemented it, so I still need to see if it's consistent...

    class AltoAlertController: UIAlertController {
    
    var alertWindow : UIWindow!
    
    func show(animated: Bool, completion: (()->(Void))?)
    {
        alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindow.Level.alert + 1
        alertWindow.makeKeyAndVisible()
        alertWindow.rootViewController?.present(self, animated: animated, completion: completion)
    }
    

    }

提交回复
热议问题