Я знаю, это почти точно на один год слишком поздно, но я надеюсь, что кто-то может использовать это. Вот как я это сделал, основываясь на ответе @ Cocoanetics:
BOOL mapReceivedDoubleTap;
...
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMap:)];
[tapGestureRecognizer setDelegate:self];
[_mapView addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
...
// ignore annotations
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return (![[touch view] isKindOfClass:[MKAnnotationView class]]);
}
// take care of double taps for zoom
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if([otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tr = (UITapGestureRecognizer *)otherGestureRecognizer;
if(tr.numberOfTapsRequired == 2)
mapReceivedDoubleTap = YES;
}
return NO;
}
- (void)didTapMap:(UITapGestureRecognizer *)tapGestureRecognizer {
mapReceivedDoubleTap = NO;
// hide/show on delay
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, .2f * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if(!mapReceivedDoubleTap)
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:YES];
});
}
Swift
import MapKit
class MapViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet weak var myMapView: MKMapView!
var mapReceivedDoubleTap = false
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(MapViewController.didTapMap(_:)))
tapGestureRecognizer.delegate = self
myMapView.addGestureRecognizer(tapGestureRecognizer)
}
// ignore annotations
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
return !touch.isKindOfClass(MKAnnotationView)
}
// take care of double taps for zoom
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if otherGestureRecognizer.isKindOfClass(UITapGestureRecognizer) {
let tr = otherGestureRecognizer as! UITapGestureRecognizer
if tr.numberOfTapsRequired == 2 {
mapReceivedDoubleTap = true
}
}
return false
}
func didTapMap(gestureRecognizer: UIGestureRecognizer) {
mapReceivedDoubleTap = false
// hide/show on delay
let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.2 * Double(NSEC_PER_SEC)))
dispatch_after(popTime, dispatch_get_main_queue(), {
if !self.mapReceivedDoubleTap {
self.navigationController?.setNavigationBarHidden(!(self.navigationController?.navigationBarHidden)!, animated: true)
}
})
}
}