MapView - 禁用Doubletap Zoom

时间:2015-07-03 04:40:39

标签: ios objective-c mkmapview mapkit uigesturerecognizer

在我的mapview中,我使用长按手势在地图上绘制MKCircle。我想使用双击手势删除圆圈。我添加双击作为手势识别器并且它可以正常工作,但是,当它移除圆圈时,它每次也会缩放一点。我想知道是否有办法通过双击行为删除默认缩放只留下我自己的?我不想在进行双击时禁用整个地图的缩放。

UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(getMapCoordinateFromTouch:)];
    [self.mapView addGestureRecognizer:longGesture ];

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeBoundary:)];
    [tapGesture setNumberOfTapsRequired:2];
    [tapGesture setNumberOfTouchesRequired:1];
    tapGesture.delegate = self;
    [self.mapView addGestureRecognizer:tapGesture];

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

-(void)removeBoundary:(UITapGestureRecognizer *)gesture
{
    [self.mapView removeOverlays:self.mapView.overlays];
}

其他信息:

有人建议此问题类似于:Disable double tap zoom in MKMapView (iOS 6)

然而,那个人试图禁用所有双击而不仅仅是默认行为。我确实在这个问题中找到了一些我觉得可能有帮助的代码,但事实并非如此。在该线程中,表明您可以遍历mapview并删除手势识别器。这似乎适用于我可能添加的手势识别器,但它没有找到任何Apple默认行为。我在viewWillAppear(我也尝试过viewDidAppear)之后运行以下代码,但是一个断点显示"手势"没有。因此,由于某种原因,该视图没有Apple的默认手势。

NSArray *gestures = [self.mapView gestureRecognizers];
    for (UIGestureRecognizer *recognizer in gestures)
    {
        if ([recognizer isKindOfClass:[UITapGestureRecognizer class]])
        {
            UITapGestureRecognizer *tap = (UITapGestureRecognizer *)recognizer;
            if (tap.numberOfTapsRequired == 2)
                [self.mapView removeGestureRecognizer:recognizer];
        }
    }

2 个答案:

答案 0 :(得分:0)

尝试从NO返回-gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:。这听起来像你的识别器和地图视图的识别器正在双击。你真的希望你的第一次破解手势,所以它可以有效地覆盖地图视图。

答案 1 :(得分:0)

默认的UIGestureRecognizers似乎已添加到第一个子视图中,只需将其删除即可:

删除所有UITapGestureRecognizers(从13到9)的示例
夫特:

<?php header('Location: yourdomain.url'); 
      exit(); //Thanks Drixson Oseña
?>

目标-C:

    print("GestureRecognizers before \(mainMap.subviews[0].gestureRecognizers?.count)")
    if (mainMap.subviews[0].gestureRecognizers != nil){
        for gesture in mainMap.subviews[0].gestureRecognizers!{
            if (gesture.isKindOfClass(UITapGestureRecognizer)){
                mainMap.subviews[0].removeGestureRecognizer(gesture)
            }
        }
    }
    print("GestureRecognizers after \(mainMap.subviews[0].gestureRecognizers?.count)")