Disable double tap in MKMapView (iOS 6)

in ios 5, I was able to disable double-tap scaling by simply overriding it with a new double-touch gesture. But it seems that the double-touch gesture is no longer in the gesturerecognizer array that comes with mkmapview.

NSArray *gestureRecognizers = [_mapView gestureRecognizers]; for (UIGestureRecognizer *recognizer in gestureRecognizers) { NSLog(@"%@", recognizer); } 

returns nothing in ios 6, where in ios 5 it returns 2 recognizers, one for one tap and one for double tap.

+6
source share
5 answers

I looked at gesture recognizers in MKMapView peeps. He's probably out there somewhere.

Of course, messing around with a different GRs look is a bit dubious and is likely to break the next time Apple changes something in MKMapView ...

EDIT: In the interest of anyone reading this, check that these are UITapGestureRecognizer and numberOfTapsRequired == 2 and numberOfTouchesRequired == 1 .

Also, instead of completely disabling double tapping on the map, consider adding a double GR tap to the annotation, and then run [mapDoubleTapGR requireGestureRecognizerToFail:annotationDoubleTapGR] . Again, hacky - don't blame me if it breaks into the next OS update!

+7
source

Do you want the user to do something with a view? If not, just set userInteractionEnabled to NO . If so, what specific interactions do you need to allow? All but double tap? Why disable this one interaction?

The more we know about your use case, the better the answers we can provide.

+2
source

This worked for me: [_mapView.subviews [0] addGestureRecognizer: MyDoubleTapOverrider];

+2
source

This works for me:

  //INIT the MKMapView -(id) init{ ... [self getGesturesRecursive:mapView]; ... } 

And then let the recursive loop function through subviews and find GR: s.

  -(void)getGesturesRecursive:(UIView*)v{ NSArray *gestureRecognizers = [v gestureRecognizers]; for (UIGestureRecognizer *recognizer in gestureRecognizers) { if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) { [v removeGestureRecognizer:recognizer]; } } for (UIView *v1 in v.subviews){ [self getGesturesRecursive:v1]; } } 

This example removes all tap-GR: s. But I think you can specify to remove anything you want.

+1
source

Instead, you can use a long highlight gesture that works.

0
source

Source: https://habr.com/ru/post/925873/


All Articles