The status bar is hidden after the deviation of the modal view and appears after a few seconds

I have a very strange behavior:

I have an application with a navigation controller (navigation bar) where the status bar is displayed. Then I present a view controller (barcode scanner using the camera) where I want to hide the status bar, so I implemented:

override func prefersStatusBarHidden() -> Bool { return true } 

When I close a modal view with

 self.dismissViewControllerAnimated(true, completion: nil) 

the view disappears and the status bar is hidden, although the rootviewcontroller implements

 override func prefersStatusBarHidden() -> Bool { return false } 

But after a few seconds, the status bar will appear automatically !?

I have a solution here in StackOverflow that I tried:

 UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Fade) self.dismissViewControllerAnimated(true, completion: nil) 

But that didn’t change anything for me.

Maybe I can do an update in the root view in viewDidAppear ??

+6
source share
2 answers

Perhaps you are calling dismissViewControllerAnimated from the background thread?

If so, try wrapping the call (and any other UIKit calls as it is not thread safe) in the GCD call back to the main queue as follows:

 dispatch_async(dispatch_get_main_queue()) { self.dismissViewControllerAnimated(true, completion: nil) } 
+8
source

You probably need to call setNeedsStatusBarAppearanceUpdate on your controller:

Call this method if the attributes of the status bar of the view controller, such as hidden / unclosed status or style, are changed. If you call this method in an animation block, the changes will be animated along with the rest of the animation block.

This is usually done in viewDidLoad , but in your case it is probably best to do this in viewDidAppear , since your view is already loaded and you reject the view further down the view hierarchy. Try the following:

 override func viewDidAppear(animated: Bool) { self.setNeedsStatusBarAppearanceUpdate() } 
+2
source

Source: https://habr.com/ru/post/980470/


All Articles