Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Navigation Bar for a View Controller

I've tried to hide the navigation controller for a single view controller with no luck, the navigation bar is hidden for the first vc, but it's not displaying for the second vc.

Here's the code I've used in the first vc:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(false, animated: animated)
}

What's changed in swift 4? That code worked in swift 3...

like image 324
Jonathan Solorzano Avatar asked Nov 07 '17 05:11

Jonathan Solorzano


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 add a navigation bar to a table view controller?

From the outline view, make sure your Table View Controller is selected. Then go to the Editor menu, and click on the Embed In submenu, and choose Navigation Controller and voila. You have your navigation controller pointing to your tableview controller with a relationship built in. This should be the selected answer.

How do I hide the navigation bar in react native?

navigationHide() Hides the navigation bar.

How do I get rid of the transparent navigation bar?

If you want to remove the opacity or transparency from the sticky navigation bar, just navigate to Theme Options -> General -> Additional CSS and copy/paste this code and save changes. You could also manipulate the opacity by altering the value “1” at the end of the CSS statement.


1 Answers

Use code:- Swift 5

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(true)
    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(false, animated: false)
}

I think you have done mistake in animated: true

like image 169
Dilip Tiwari Avatar answered Sep 22 '22 23:09

Dilip Tiwari