When using UINavigationController in your iOS, iPadOS and macOS app sometimes you need to show/hide the navigation bar on a particular view and here is how to do it without disturbing the navigation bar hierarchy in your Main.storyboard file.

Sometimes you want to hide Navigation Bar from a particular view without manually deleting it from Main.storyboard,

So here I have documented how to do it programmatically instead.

Step 01: Copy the following code to your ViewController’s Swift file’s ‘viewWillAppear’ method for which view you want to hide Navigation Bar on its load on your iPhone, iPad or Mac’s (Catalyst) app screen.

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}

Step 02: Now copy the following code to your ViewController’s ‘viewWillDisappear’ method on your same View Controller’s Swift file so it will not hurt other view controllers in the hierarchy when you move away from your original view controller.

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

Hope it helps,

Thanks & Regards
Mandar Apte

Mandar Apte

This website contains a design articles blog by Mandar Apte. He writes and shares his iOS development, graphic, web, & animation film design experience through articles. Mandar is Mumbai based multi-disciplinary designer with expertise in UI, UX, Logo, Symbol, and Brand Identity design. He is an alumnus of Sir J. J. Institute of Applied Art, Mumbai. He currently runs his studio in the heart of the city of Mumbai.

Leave a Reply

Your email address will not be published. Required fields are marked *