My task is to deselect a map annotatnion on second tap.
I didn’t find how to do it with mapView functions. So I used an article from stackoverflow and do like this:
- (void)viewDidLoad
{
annotationTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annotationTapRecognized:)];
annotationTap.numberOfTapsRequired = 1;
annotationTap.delegate = self;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[view addGestureRecognizer:annotationTap];
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
[view removeGestureRecognizer:annotationTap];
}
- (void)annotationTapRecognized:(UIGestureRecognizer *)gesture
{
NSArray *selectedAnnotations = self.viewMap.selectedAnnotations;
for (MapAnnotation *annotationView in selectedAnnotations) {
[self.viewMap deselectAnnotation:annotationView animated:NO];
}
}
It seems works correct, but it is not. When I tap on the annotation second time callout disappears and appears again.
Any ideas?
Thanks in advance.
I’ve found the solution. Maybe it’s not good.
I’ve added boolean “is show”, as luxsypher mentioned. So my functions looks like the following:
Maybe it will be useful for somebody :).
Thanks.