Reputation: 746
I want one of my pushed viewControllers in a navigation controller stack to be "full screen" - no navigation bar and no status bar. I have this code that hides and shows the navigation bar in one of the view controllers of navigation controller (I want it to be pushed on full screen):
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated:animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated:animated)
}
In the same viewController I'm also hiding the status bar with this:
override var prefersStatusBarHidden: Bool {
return true
}
It is hiding and showing as expected but the problem is that I get a black stripe on the transition when pushing this view controller and back from it (see images).
Push to this controller: Push to this controller
And back from this controller (back button):
It appears this is happening because of the prefersStatusBarHidden function Removing this solves the issue.
The code for show/hide the nav bar is taken from: https://stackoverflow.com/a/2406167/4207465
and based on apple developer library: "Showing and Hiding the Navigation Bar - When a navigation bar is used in conjunction with a navigation controller, you always use the setNavigationBarHidden:animated: method of UINavigationController to show and hide the navigation bar..."
Not sure why it's happening, Thanks for the help!
Upvotes: 1
Views: 2441
Reputation: 228
@Boaz Frenkel
There is one solution to fix the black strip during hide and show of navigation bar with or without status bar.
ViewController A : Fullscreen View
override func viewWillAppear(animated: Bool) {
self.navigationController?.setNavigationBarHidden(true, animated: animated)
super.viewWillAppear(animated)
}
override func viewDidAppear(animated: Bool) {
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade)
super.viewDidAppear(animated)
}
ViewController B : With NavigationBar and status bar
override func viewWillAppear(animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .None)
super.viewWillAppear(animated)
}
Upvotes: 1
Reputation: 1377
Please try to hide navigation bar in viewDidAppear. Now you're hidding bar before showing controller.
func viewDidAppear(_ animated: Bool) {
super. viewDidAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
Upvotes: 0