longpress手势识别器不适用于地图视图上的用户位置(MKuserlocation) - iOS

时间:2013-06-14 09:58:13

标签: iphone ios location mkmapview gesture

我的应用程序中有一个MapView。 Showuserlocation处于活动状态。 我添加了GestureRecognizer进行长按。 一切正常。

通过利弊,当我触摸用户的注释(蓝色圆圈)时,手势事件不会被接收。

如何拦截用户注释上的手势?

谢谢你的帮助。

3 个答案:

答案 0 :(得分:2)

您可以通过修改上述代码中的微小更改来添加手势以检测长按。

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
    {



    UILongPressGestureRecognizer* _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)];
    _longPressRecognizer.minimumPressDuration = 0.0;
    _longPressRecognizer.accessibilityValue = [NSString stringWithFormat:@"%d",totalMenues];
    [pinView addGestureRecognizer:_longPressRecognizer];

    }

    - (void) longPressDetected:(UIGestureRecognizer*) gestureRecognizer
    {

    }

答案 1 :(得分:1)

您没有在注释上添加手势。因此您需要为每个注释添加手势。由于有两种方法,因此无需向注释添加手势。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view

如果你想那么

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation)annotation
{
    // Reuse or create annotation view

    UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapRecgonized:)];
    longTap.delegate = self;
    [annotationView addGestureRecognizer:longTap];
}

- (void)longTapRecognized:(UITapGestureRecognizer *)recognizer
{
    // Handle double tap on annotation view
}

答案 2 :(得分:0)

您是否实施了UIGestureRecognizerDelegate的后续方法?

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

该方法应该返回YES,因此手势识别器可以与其他人一起使用。

相关问题