I have a MKMapView
, which zooms in when double tapped (default behavior). I want to add a triple tap gesture recognizer to the map view that zooms out again to a certain initial zoom level.
The problem is that the built-in double tap recognizer fires first. In order to delay this, one had to access the double tap recognizer in some way, but at least in iOS6 the view
property gestureRecognizers
does not contain the double tap recognizer of the map view.
So, is it possible to delay the double tap recognizer in some way in order to allow the triple tap recognizer to fire first?
Check out the instance method requireGestureRecognizerToFail
in the UIGestureRecognizer
class.
http://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/instm/UIGestureRecognizer/requireGestureRecognizerToFail:
Creates a dependency relationship between the receiver and another gesture recognizer.
For example:
[doubleTap requireGestureRecognizerToFail:tripleTap];
After goofing around with it for a bit, I've got it working like this (assuming you've got an MKMapView
named mapView
):
UITapGestureRecognizer *tripleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTripleTap:)];
tripleTap.numberOfTapsRequired = 3;
[mapView.subviews[0] addGestureRecognizer:tripleTap];
UIView *tempMapView = mapView.subviews[0];
NSArray *mapGestures = tempMapView.gestureRecognizers;
UITapGestureRecognizer *tempMapDoubleTap = mapGestures[0];
[tempMapDoubleTap requireGestureRecognizerToFail:tripleTap];
NSLog(@"%@", mapGestures);
Triple Tap Selector:
- (void)handleTripleTap:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"Triple Tap Detected..");
}
Now double-tapping still zooms the MKMapView
and triple-tapping successfully executes handleTripleTap
without zooming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With