I have made following common method for hiding and showing again status bar. It works fine before iOS 13, but I am getting following crash while I run it for device having iOS 1
If you want to show/hide the status bar on the different View Controllers you need to:
var prefersStatusBarHidden: Bool
in each View Controller where you want to have the status bar shown/hiddenoverride var prefersStatusBarHidden: Bool {
return true
}
If you want to show/hide it dynamically (ex. after tapping on button), you could do something like this:
var statusBarHidden = true {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
override var prefersStatusBarHidden: Bool {
return statusBarHidden
}
You could find more verbose explanation here Here
Also in the Apple Documentation for UIStatusBarManager
you can find the following quote:
You do not use this object to modify the configuration of the status bar. Instead, you set the status bar configuration individually for each of your UIViewController objects. For example, to modify the default visibility of the status bar, override the prefersStatusBarHidden property of your view controller.