Navigation bar show/hide
This isn't something that can fit into a few lines of code, but this is one approach that might work for you.
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To show it:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
Documentation for this method is available here.
To listen for a "double click" or double-tap, subclass UIView
and make an instance of that subclass your view controller's view
property.
In the view subclass, override its -touchesEnded:withEvent:
method and count how many touches you get in a duration of time, by measuring the time between two consecutive taps, perhaps with CACurrentMediaTime()
. Or test the result from [touch tapCount]
.
If you get two taps, your subclassed view issues an NSNotification
that your view controller has registered to listen for.
When your view controller hears the notification, it fires a selector that either hides or shows the navigation bar using the aforementioned code, depending on the navigation bar's current visible state, accessed through reading the navigation bar's isHidden
property.
EDIT
The part of my answer for handling tap events is probably useful back before iOS 3.1. The UIGestureRecognizer
class is probably a better approach for handling double-taps, these days.
EDIT 2
The Swift way to hide the navigation bar is:
navigationController?.setNavigationBarHidden(true, animated: true)
To show it:
navigationController?.setNavigationBarHidden(false, animated: true)
This code will help you.
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];
}
}