You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we add another UIWindow, then its rootViewController will decide the style of the status bar, not the rootViewController of the keyWindow anymore
childForStatusBarStyle
The usual way to fix this is to defer the decision to the correct rootViewController, like in our HUDViewController
classHUDViewController:UIViewController{overridevarchildForStatusBarStyle:UIViewController?{letwindows= view.window?.windowScene?.windows ??[]
for window in windows where window !=self.view.window {return window.rootViewController?.childForStatusBarStyle
}returnnil}}
This works, but in case we present some view controllers, the status bar now lays on a dark content. And we don't know when to call setNeedsStatusBarAppearanceUpdate for childForStatusBarStyle to kick in again
Overriding rootViewController
A workaround is to override rootViewController to return the keyWindowrootViewController instead
finalclassHUDWindow:UIWindow{overridepublicvarrootViewController:UIViewController?{get{
for window in windowScene?.windows whereself!= window {
if let rootViewController = window.rootViewController {return rootViewController
}}return super.rootViewController
}set{
super.rootViewController = newValue
}}}
This comes with another problem: our HUDWindow now propagates the safeAreaInsets to the keyWindowrootViewController instead of its own rootViewController, resulting in wrong area insets for the HUD content.
One way to fix this is to listen to safeAreaInsetsDidChange. I found out that by altering additionalSafeAreaInsets, the view controller somehow invalidates its safeAreaInsets
When we add another
UIWindow
, then its rootViewController will decide the style of the status bar, not the rootViewController of thekeyWindow
anymorechildForStatusBarStyle
The usual way to fix this is to defer the decision to the correct
rootViewController
, like in ourHUDViewController
This works, but in case we present some view controllers, the status bar now lays on a dark content. And we don't know when to call
setNeedsStatusBarAppearanceUpdate
forchildForStatusBarStyle
to kick in againOverriding rootViewController
A workaround is to override
rootViewController
to return thekeyWindow
rootViewController
insteadThis comes with another problem: our HUDWindow now propagates the
safeAreaInsets
to thekeyWindow
rootViewController
instead of its ownrootViewController
, resulting in wrong area insets for the HUD content.One way to fix this is to listen to
safeAreaInsetsDidChange
. I found out that by alteringadditionalSafeAreaInsets
, the view controller somehow invalidates itssafeAreaInsets
Another way is to reach to
safeAreaInsets
from the window instead. For example fromHUDViewController
modalPresentationCapturesStatusBarAppearance
modalPresentationCapturesStatusBarAppearance
We can set
modalPresentationCapturesStatusBarAppearance
tofalse
to prevent the hud view controller from taking over the status bar style decisionThe text was updated successfully, but these errors were encountered: