Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status bar keeps hidden after dismiss modal view and appears after some seconds

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??

like image 311
mahega Avatar asked Jan 03 '15 15:01

mahega


2 Answers

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)
}
like image 128
James Nick Sears Avatar answered Oct 31 '22 19:10

James Nick Sears


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()
}
like image 36
AstroCB Avatar answered Oct 31 '22 20:10

AstroCB