Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing/hiding navigation bar with smooth animation

I have a navigation based app. The first view (rootcontroller) starts with three large buttons only. No navigationbar. From there, everything else is tableviews and have navigation bars. I'm doing this to show/hide the navigation bar:

MyAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.navigationController.navigationBar.hidden = NO; 

Once I leave the root controller, the navigation bar will jerk into place and lay on top of the tableview, rather than pushing it down. It clips the top part of the tableview. Going back to the root controller isn't smooth in how the navigation bar disappears. Is there a smoother/better way to do accomplish hiding the navigation bar for the root controller only?

like image 722
4thSpace Avatar asked Jan 17 '10 01:01

4thSpace


People also ask

How do I show hidden navigation bar?

The navigation bar is pinned by default. If you want to view files or use apps in full screen, double-tap the Show and hide button to hide the navigation bar. To show the navigation bar again, drag upwards from the bottom of the screen.

How do I hide the navigation bar when not in use?

Go to Settings > Display > Navigation Bar. Tap the toggle beside Show and hide button to switch it to the on position. If you don't see this option, check for any available software updates. The update might not be out all carrier-specific Galaxy S8 phones yet.

How do I hide navigation bar in storyboard?

Click on the controller that has the top bar navigate to the properties bar on the right hand side of Xcode. There is a drop down labeled Top Bar (as shown above) change this drop down to none.


2 Answers

You can use [navigationController setNavigationBarHidden:YES animated:YES] to hide the bar smoothly.

Reference

like image 68
James Avatar answered Oct 12 '22 18:10

James


This nifty bit of code animates the navigation bar hiding with no UI issues:

[navigationController setNavigationBarHidden: YES animated:YES]

But...

  1. Use the self.navigationController.navigationBarHidden property for checks in the code instead of the self.navigationController.navigationBar.hidden property. This will save you a lot of pain from unexpected UI positioning problems.
  2. Take care to place this method in - (void)viewWillAppear:(BOOL)animated or later in the view lifecycle. This is recommended because if you do it in - (void)viewDidLoad for instance, you will get an ugly black rectangular view during animations from a view which displays its navigation bar to a view which doesn't! For example, if your home view has its navigation bar hidden but all its children have the navigation bar shown, when you pop to home view, the animation will show a black bar in place of the navigation bar until the animation completes
like image 36
codeburn Avatar answered Oct 12 '22 19:10

codeburn