Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Navigation Bar in Specific View - Swift 3

I have NavigationController that handles navigation through my app. According to my design, the very first view should have no visible NavigationBar. All the others after, will.

In this FirstView, I'm using this so far to hide the NavBar, inside the ViewDidLoad:

self.navigationController?.isNavigationBarHidden = true

From this FirstView I can access other Views. In these other views I show the NavBar using:

self.navigationController?.isNavigationBarHidden = false

My problem is that:

  • When I navigate from a View with Visible NavBar, back to the FirstView with the Hidden NavBar, the NavBar is now visible. Basically the NavBar only hides the very first time then shows if I use the back button.

How Can I Prevent this ?

Thank you!

like image 533
Quentin Beau Kwint Avatar asked May 02 '17 09:05

Quentin Beau Kwint


People also ask

How do I hide the navigation bar?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide the tab bar in Swift?

hidesBottomBarWhenPushed = true should do the work. DO NOT manually show and hide the tabbar.

How do you make a navigation bar transparent in Swift?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ).

How do you hide the navigation title in Swift?

There's a really easy way to make this happen, and it's a property on UINavigationController called hidesBarsOnTap . When this is set to true, the user can tap anywhere on the current view controller to hide the navigation bar, then tap again to show it.


1 Answers

Move that code to viewWillAppear() instead of viewDidLoad().

viewDidLoad() is only called once per instantiated view controller, whereas viewWillAppear() is called whenever the view controller is about to be presented on screen.

You can read more about the view controller lifecycle here.

like image 166
Eggsalad Avatar answered Sep 17 '22 22:09

Eggsalad