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