I have an app that presents modally View Controllers, I have a standard ViewController and an UIAlertController in different UIWindows, the main with normal UIWindowLevel priority and the Alert window with Alert UIWindowLevel priority, because I want to always have the alert on top of whatever ViewController I present modally on the main UIWindow (AppDelegates reference). I also have another UIWindow with Status Bar priority, for moments when I want for sure to have a different ViewController on top of everything. So when I present the UIWindow with a Alert UIWIndowLevel priority and after I present a different window with Status Bar UIWIndowLevel the alert in the Alert Window is displaying on top of the Status Bar window. Is there a reason for that?
-
Well, an alert is supposed to be something that is more important than anything else, and needs immediate attention from the user. So it is not surprising that it displays over everything else. – fishinear Jun 21 '17 at 13:35
-
But since UIAlertController is an ViewController that works on top of windows, a different window, with a different level should override an alert VC. – fredy Jun 21 '17 at 17:34
1 Answers
So, I was looking at some of the many SOs opened and saw this answer: https://stackoverflow.com/a/24262942/6784707
I printed the values of (UIWindowLevelNormal, UIWindowLevelAlert, UIWindowLevelStatusBar) are (0.0, 2000.0, 1000.0). But Apple's documentations states that:
let UIWindowLevelNormal: UIWindowLevel
The default level. Use this level for the majority of your content, including for your app’s main window.
let UIWindowLevelAlert: UIWindowLevel
The level for an alert view. Windows at this level appear on top of windows at the UIWindowLevelNormal level.
let UIWindowLevelStatusBar: UIWindowLevel
The level for a status window. Windows at this level appear on top of windows at the UIWindowLevelAlert level.
I filled a bug in Apple's Bug Reporter.
My solution was to create a CGFloat with value over 2000 and add it to windowLevel.