Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone hide Navigation Bar only on first page

I have the code below that hides and shows the navigational bar. It is hidden when the first view loads and then hidden when the "children" get called. Trouble is that I cannot find the event/action to trigger it to hide again when they get back to the root view....

I have a "test" button on the root page that manually does the action but it is not pretty and I want it to be automatic.

-(void)hideBar  {     self.navController.navigationBarHidden = YES; } -(void)showBar  {            self.navController.navigationBarHidden = NO; } 
like image 545
Lee Armstrong Avatar asked May 10 '09 16:05

Lee Armstrong


People also ask

How do I hide navigation bar on Iphone?

You can find the Website View menu in what's called the Smart Search field at the top of the Safari interface. Launch the app and navigate to a website, then tap the "aA" icon in the upper left corner of the screen. Simply select Hide Toolbar from the dropdown menu, and the toolbar will shrink to show just the URL.

How do I hide the top navigation bar in Swift?

How To Hide Navigation Bar In Swift. To hide the navigation bar in Swift, you'll need to add code to two methods: viewWillAppear and viewWillDisappear . That's it to hide the navigation bar in your view controller.

What is a navigation controller Swift?

A navigation controller is a container view controller that manages one or more child view controllers in a navigation interface. In this type of interface, only one child view controller is visible at a time.


1 Answers

The nicest solution I have found is to do the following in the first view controller.

Objective-C

- (void)viewWillAppear:(BOOL)animated {     [self.navigationController setNavigationBarHidden:YES animated:animated];     [super viewWillAppear:animated]; }  - (void)viewWillDisappear:(BOOL)animated {     [self.navigationController setNavigationBarHidden:NO animated:animated];     [super viewWillDisappear:animated]; } 

Swift

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

This will cause the navigation bar to animate in from the left (together with the next view) when you push the next UIViewController on the stack, and animate away to the left (together with the old view), when you press the back button on the UINavigationBar.

Please note also that these are not delegate methods, you are overriding UIViewController's implementation of these methods, and according to the documentation you must call the super's implementation somewhere in your implementation.

like image 65
Alan Rogers Avatar answered Oct 21 '22 22:10

Alan Rogers