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
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showHideNavbar:)];
[self.view addGestureRecognizer:tapGesture];
-(void) showHideNavbar:(id) sender
{
if (self.navigationController.navigationBar.hidden == NO)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
else if (self.navigationController.navigationBar.hidden == YES)
{
[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.