Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Tap to MKMapView without breaking double tap zoom

Tags:

I want to drop a pin on my MKMapView when the user single taps on the map. I have the pin code working, I have the single tap working, but when I double tap to zoom I get a single tap first. Here's my code to get the recognizers setup:

    self.doubleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleDoubleTap:)];
    self.doubleTap.numberOfTapsRequired = 2;
    self.doubleTap.numberOfTouchesRequired = 1;
    [mapView_ addGestureRecognizer:doubleTap_];

    self.singleTap = [[UITapGestureRecognizer alloc]
                      initWithTarget:self action:@selector(handleGesture:)];
    self.singleTap.numberOfTapsRequired = 1;
    self.singleTap.numberOfTouchesRequired = 1;
    [self.singleTap requireGestureRecognizerToFail: doubleTap_];
    [mapView_ addGestureRecognizer:singleTap_];

Now, this is not surprising, to quote Apple:

Note: In the case of the single-tap versus double-tap gestures, if a single-tap gesture recognizer doesn’t require the double-tap recognizer to fail, you should expect to receive your single-tap actions before your double-tap actions, even in the case of a double tap. This is expected and desirable behavior because the best user experience generally involves stackable actions.

So I added requireGestureRecognizerToFail to my single tap recognizer.

[singleTap requireGestureRecognizerToFail: doubleTap];

and this ensures that my single tap recognizer doesn't get double taps.

But...

Now my double tap recognizer gets the double taps and MKMapView doesn't get them. I've tried setting cancelsTouchesInView to NO in the recognizer, but that didn't help either.

So I need a way to either prevent my single tap recognizer from getting double taps (which seems unlikely) or to get my double tap event to my mapView.