Click here to Skip to main content
15,881,803 members
Articles / Mobile Apps / iPhone

How to Show Hide Navigation Bar When Tap in iOS Occurs

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Dec 2012CPOL 26.4K   4  
A quick tip that will show you how to show hide Navigation Bar when tap in iOS occurs

This is a quick tip that will show you how to show hide Navigation Bar when tap in iOS occurs. This is a great method if you want to benefit from every pixel of the screen real estate. So I suggest you do it when you have a view that will display images in fullscreen. An example is when you want to show hide Navigation Bar when the user taps the screen.

A lot of top apps use the show hide Navigation Bar, mainly when opening an image. Twitter, Facebook, eBay and a plethora of famous apps are using this technique. Why not you?

I will show you how in these simple steps in the following code.

Code for show/hide Navigation Bar

C++
UITapGestureRecognizer *tapGesture = 
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showHideNavbar:)];
[self.view addGestureRecognizer:tapGesture];
 
-(void) showHideNavbar:(id) sender 
{ 
// write code to show/hide nav bar here 
// check if the Navigation Bar is shown
if (self.navigationController.navigationBar.hidden == NO)
{
   // hide the Navigation Bar
   [self.navigationController setNavigationBarHidden:YES animated:YES];
}
// if Navigation Bar is already hidden
else if (self.navigationController.navigationBar.hidden == YES)
{
   // Show the Navigation Bar
   [self.navigationController setNavigationBarHidden:NO animated:YES];
}
}

That’s all guys, now you got another tool that will make your app look cooler and more functional.

If you have any other idea of how to implement this thing, please leave a comment.

You can follow me on Twitter in my personal profile or Duuro App Studio profile.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Albania Albania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --