Here is what I want - user taps on the map, my code gets executed and then system code is executed (if user clicked on annotation callout is presented etc...).
I added simple tap recognizer to map view:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapViewTapped:)];
[self.mapView addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
Inside mapViewTapped my code gets executed. Now I want to notify system code of tap (for example to show callout). How do I do that? How to pass event that I intercepted?
One way is to implement the
UIGestureRecognizerDelegate
methodgestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
and returnYES
in it:Now your
mapViewTapped:
will get called and then the map view's recognizer will call its method. If the tap was on an annotation view, the map view will show its callout (and thedidSelectAnnotationView
delegate method will get called if you've implemented it).Another way, if you need more control, then instead of doing the above, in your
mapViewTapped:
you can check if the tap was on an annotation view and then manually select the annotation which will then show its callout (and call thedidSelectAnnotationView
delegate method):