How to hide navigation bar immediately in Swift?

25,551

Solution 1

According the official document:

Every app must supply a launch file or at least one static image.

The delay is caused by the launch screen from the your main storyboard file. Don't set launch screen file to your Main.storyboard file.

In Project settings > General -> App Icons and Launch Images -> Launch Screen File:

enter image description here

Set it to another storyboard:

enter image description here

Solution 2

hide the navgationBar when the ViewController init ViewController.navigationController?.setNavigationBarHidden(true, animated: false)

Solution 3

A better way is to implement your code in viewWillLayoutSubviews(). It's a better approach if you use navigation or tapbar

Swift 4 :

override func viewWillLayoutSubviews() {
    self.navigationController?.isNavigationBarHidden = true
}

Solution 4

#Add this line indside view did load method

override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.isNavigationBarHidden = true
    }

##Otherwise directly do this from StoreyBoard

//Set Top Bar None

[![enter image description here][1]][1] [1]: http://i.stack.imgur.com/CGIsC.png

I hope this will help you.

Solution 5

Try this...

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

    self.navigationController?.navigationBarHidden = true
}
Share:
25,551
Cody
Author by

Cody

Updated on January 06, 2021

Comments

  • Cody
    Cody over 3 years

    My UIViewController is embed in a navigation controller:

    enter image description here

    I tried setNavigationBarHidden:animated: to hide notificationbar. It works but there are about 2 seconds delay. Here is the screenshot:

    enter image description here

    My usage is to add it in viewDidLoad():

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
    

    How to hide navigationbar immediately when screen is launched ?