How to hide navigation bar immediately in Swift?
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
:
Set it to another storyboard:
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
}
Cody
Updated on January 06, 2021Comments
-
Cody over 3 years
My UIViewController is embed in a navigation controller:
I tried setNavigationBarHidden:animated: to hide notificationbar. It works but there are about 2 seconds delay. Here is the screenshot:
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 ?