Show/hide the navigation bar on a particular view without disturbing the navigation bar hierarchy in iOS/iPadOS app.

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

So, 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 the 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 view controller’s ‘view will disappear’ 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

Published by Mandar Apte

Mandar is a Mumbai-based multi-disciplinary designer with UX/UI, Logo, Symbol, and Brand Identity design expertise. He currently runs his Mudrkashar Linguistic Apple iPhone, iPad, and Mac app business in the heart of Mumbai city.

Leave a comment

Leave a Reply