I'm trying to get the updated status bar frame height using didChangeStatusBarFrame
, but…
The new/updated frame isn't up-to-date and sometimes returns the old and sometimes the new (correct) height.
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
print(UIApplication.shared.statusBarFrame.height) // Sometimes wrong
}
My current workaround is to use DispatchQueue.main.async
:
func application(_ application: UIApplication, didChangeStatusBarFrame oldStatusBarFrame: CGRect) {
DispatchQueue.main.async {
print(UIApplication.shared.statusBarFrame.height) // So far correct in all my tests
}
}
I guess it's because some layout is happening in the background and the statusBarFrame
needs to update first.
What's the real reason and is there a better, not-so-hacky way to wait for the correct status bar frame height?