Disable double tap zoom in MKMapView (iOS 6)

2019-02-17 09:54发布

in ios 5 i was able to disable the double tap zoom by just overriding it with a new double tap gesture. But it seems that the double tap gesture is no longer in the gesturerecognizer array that comes with the mkmapview.

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

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

5条回答
男人必须洒脱
2楼-- · 2019-02-17 10:02

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-17 10:04

Do you want to let the user do anything with the view? If not, it sufficient to set userInteractionEnabled to NO. If so, what specific interactions do you need to allow? Everything but double-tapping? Why disable that one interaction?

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

查看更多
Emotional °昔
4楼-- · 2019-02-17 10:09

You can use a long tap gesture instead, that works.

查看更多
小情绪 Triste *
5楼-- · 2019-02-17 10:19

This works for me:

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

And then let the recursive function loop through the subviews and find the 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 guess you can specify to remove whatever you'd like.

查看更多
Luminary・发光体
6楼-- · 2019-02-17 10:20

I'd look through the gesture recognizers of MKMapView's subviews. It's probably still there somewhere.

Of course, messing around with another view's GRs is slightly dubious and will likely break the next time Apple changes something about MKMapView...

EDIT: For the benefit of anyone else reading this, please check that it's a UITapGestureRecognizer and that numberOfTapsRequired == 2 and numberOfTouchesRequired == 1.

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

查看更多
登录 后发表回答