Showing NavigationBar and StatusBar when pushed from a view controller

665 views Asked by At

I have a view controller that hides both navigationBar and statusBar. When the viewController pushes to a new viewController, where I want to show both navigationBar and statusBar, the result is like this:

enter image description here

In viewDidLoad, I do this:

self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.setNavigationBarHidden(false, animated: false)
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)

If I tap on one of the tab items in my application, and then return back to the same tab that shows the view controller, the navigationBar is shown correctly without the black bar:

enter image description here

Any idea how I can show the navigationBar correctly?

1

There are 1 answers

2
AudioBubble On

Here's how I do it:

Navigation Bar (set this in every view controller)

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.isNavigationBarHidden = true
}

Status Bar (set this in every view controller)

override var prefersStatusBarHidden: Bool {
    return true
}

Obviously, set true/false as needed. By doing this in every view controller you are insuring things behave the way you want (true == hide).