On my mapview, I draw polygon overlays that belong to a specific annotation. I want this annotation to be selected when listening to an overlay. My first attempt was to add UITapGestureRecognizerto the mapview, check if the intersection point is inside the polygon and execute [mapView selectAnnotation:myAnnotation]if it was successful. The problem is that after this mapview decides that there is a crane not on any annotations, so it cancels the annotation again.
My question is how best to prevent this; I seem to be unable to find a suitable solution. What I tried:
- Create a new subclass
UIGestureRecognizerthat recognizes only the taps inside the overlays, then iterates through mapView.gestureRecognizersand calls requireGestureRecognizerToFailfor each. However, mapview does not reveal any resolvers through its property. - Return
YESfor shouldBeRequiredToFailByGestureRecognizerto my custom recognizer for any other recognizer that isKindOfClassrecognizes the icon. However, there seems to be another recognizer that is not passed there. - Place a transparent view of it and do a polygon check
pointInside:withEvent, but also blocks any other gestures except just taps.
EDIT:
After I looped several times already, I have a code that almost works, about which I know where it goes wrong. I have a custom recognizer, as before. In my business, I do this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
{
[otherGestureRecognizer requireGestureRecognizerToFail:gestureRecognizer];
return YES;
}
. , :
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView
{
[mapView setRegion:self.displayRegion animated:YES];
}
, .