Okay, so this become a problem for me since iOS 9 doesn't support any above the method people have mentioned here such as UIApplication.sharedApplication().statusBarHidden = true
or
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
and
override func prefersStatusBarHidden() -> Bool {
return true
}
works but does not provide programable solution where I can change on a condition.
(statusBarHidden = true
and statusBarHidden = false
as we have done before).
Solution to this madness:
By adding to prefersStatusBarHidden()
like below you can programmatically control the hide and show of status bar without adding UIViewControllerBasedStatusBarAppearance
setting to your info.plist:
var showStatusBar = true
override func prefersStatusBarHidden() -> Bool {
if showStatusBar {
return false
}
return true
}
private func showStatusBar(enabled: Bool) {
showStatusBar = enabled
prefersStatusBarHidden()
}
then use it like this throughout your code:
//Hide Status Bar
showStatusBar(false)
OR
//Show Status Bar
showStatusBar(true)