1
votes

I have a MapView in my application. Showuserlocation is active. I added GestureRecognizer for long press. Everything works correctly.

By cons, when I touch the annotation of the user (blue circle), the gesture event is not receive.

how can intercepted the gesture on the annotation of the user?

thank you for your help.

3

3 Answers

2
votes

You can add gesture to detect long press by modifying with minor change in above code.

 - (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
votes

You are not adding gesture on annotation.So you need to add gesture to every annotation.And there is no need to add gesture to annotation because of there are two method.

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

If you wanna then

- (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
}
0
votes

Have you implemented follwing method of UIGestureRecognizerDelegate?

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

The method should return YES, so gesture recognizer works with others.