Click here to Skip to main content
Click here to Skip to main content
Technical Blog

How to show hide Navigation Bar when tap in iOS

, 19 Dec 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This is 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 doing it when you have an 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

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 a more functional.

If you have any other idea how to implement this thing, 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)

Share

About the Author

Perjan

Albania Albania
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411028.1 | Last Updated 19 Dec 2012
Article Copyright 2012 by Perjan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid