I have been working on an iOS app that, before iOS 13, was able to 'darken" the status bar when a pop-up appeared. This was simply done by adding a view with bounds the as the status bar and applying a .5 alpha to it:
lazy var fadeStatusBar: UIView = {
let fadeStatusBar = UIView(frame: UIApplication.shared.statusBarView?.frame ?? UIApplication.shared.statusBarFrame)
fadeStatusBar.backgroundColor = UIColor.black
fadeStatusBar.alpha = 0
fadeStatusBar.translatesAutoresizingMaskIntoConstraints = false
return fadeStatusBar
}()
Where statusBarView
is an extension of UIApplication:
extension UIApplication {
var statusBarView: UIView? {
if #available(iOS 13.0, *) {
let tag = 38482458385
if let statusBar = self.keyWindow?.viewWithTag(tag) {
return statusBar
} else {
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
statusBarView.tag = tag
self.keyWindow?.addSubview(statusBarView)
return statusBarView
}
} else {
if responds(to: Selector(("statusBar"))) {
return value(forKey: "statusBar") as? UIView
}
}
return nil
}
}
And then I could animate the fadeStatusBar alpha property to .5. However, this does not work anymore in iOS 13. I am merely wondering if it is at all still possible to accomplish, because I read in another thread that native iOS apps have removed this ability as well:
The status bar is rendered by a system process (out of the app process) on iOS 13 so there is no way for an app to change this. (Source: speaking to UIKit engineers at the WWDC 2019 labs.)
You can see this in the Apple Books app, which used to dim the status bar in its dark mode on iOS 12, but this does not happen on iOS 13.
My question differs from the one referenced above, though, because the question there is to edit the alpha of the status bar itself, while I would be glad to use an overlay view instead. Any suggestion to achieve the desired result would be appreciated.