I have a very strange behavior:
I have an app with navigation controller (navigation bar) where status bar is visible. Then I present a view controller (barcode scanner using camera) modally where I want to hide the status bar, so I implemented:
override func prefersStatusBarHidden() -> Bool {
return true
}
When I close the modally presented view using
self.dismissViewControllerAnimated(true, completion: nil)
the view disappears and the status bar keeps hidden, although the rootviewcontroller implements
override func prefersStatusBarHidden() -> Bool {
return false
}
But after some seconds the status bar appears automatically!?
I a solution here at StackOverflow which I tried:
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade)
self.dismissViewControllerAnimated(true, completion: nil)
But this doesn't changed anything for me.
Maybe I can make a refresh in the rootview in viewDidAppear??
Are you possibly calling dismissViewControllerAnimated
from a background thread?
If so, try wrapping the call (and any other calls to UIKit as it is not thread-safe) in a GCD call back to the main queue like this:
dispatch_async(dispatch_get_main_queue()) {
self.dismissViewControllerAnimated(true, completion: nil)
}
You probably need to call setNeedsStatusBarAppearanceUpdate
on your view controller:
Call this method if the view controller's status bar attributes, such as hidden/unhidden status or style, change. If you call this method within an animation block, the changes are animated along with the rest of the animation block.
Typically, this is done in viewDidLoad
, but in your case it's probably better to do it in viewDidAppear
since your view has already loaded and you are dismissing a view further down the view hierarchy. Try this:
override func viewDidAppear(animated: Bool) {
self.setNeedsStatusBarAppearanceUpdate()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With