1

I have a MKMapView with some MKPolygons and a few Custom Annotations. When ill try to tap on a Annotation Inside a MKPolygon, the trigger for the polygon always gets fired.

Can i prevent this? Ill already check on Polygon tap:

func handleMapTap(tap: UITapGestureRecognizer!) {

var tapPoint = tap.locationInView(self.mapView)

var tapCoord: CLLocationCoordinate2D = self.mapView.convertPoint(tapPoint, toCoordinateFromView: self.mapView)
var mapPoint: MKMapPoint = MKMapPointForCoordinate(tapCoord)
var mapPointAsCGP: CGPoint  = CGPointMake(CGFloat(mapPoint.x),CGFloat(mapPoint.y))

for overlay in self.mapView.overlays {

    if(overlay.isKindOfClass(MKPolygon)) {

This is how it looks like:

enter image description here

Any ideas? Can i make a "Larger" Area for an annotion, so i do not fire both events, for the Annotation AND the MKPolygon?

Edit: Thanks Anna,

ill tried that, but it brings me an "found nil while unwrapping an Optional value" error when ill try with:

var v:UIView = mapView.hitTest(mapPointAsCGP, withEvent: nil)! // error
if(v.isKindOfClass(CustomPointAnnotation) == true) {
derdida
  • 14,784
  • 16
  • 90
  • 139
  • Is didSelectAnnotationView firing? You could always trap it here and do what you want. – Mark McCorkle Apr 22 '15 at 14:19
  • Yes, it fires. But, when ill press on an Annotation ON a MKPolygon, both get fired. So you mean ill should check which one gets first fired, and maybe deactivate the second event? – derdida Apr 22 '15 at 14:22
  • Problem: the MKPolygon fires first. So i am unable to check if there is also an annotation selected. The only change is to build a delay, but i dont think thats a good choice. – derdida Apr 22 '15 at 14:24
  • Can you check to see if you are over a annotation then ignore the touch then manually select the annotation? I'm curious if you can create a subclass of MKAnnotationView and add gestureRecognizerShouldBegin and return no. – Mark McCorkle Apr 22 '15 at 14:26
  • I think thats the correct way - but i dont know how to do that. In my "handleMapTap" function ill get the tapPoint - so ill should check if there is an annotation on this point. I will try to check google, if i can find more information about that. Thanks for pointing me into a (hopefully) good direction! – derdida Apr 22 '15 at 14:31
  • The more I think about it I would subclass the MKAnnotationView and use that to trap the touch if possible. – Mark McCorkle Apr 22 '15 at 14:36
  • You can use hitTest in the gesture handler (tap.view won't work because it will always be the MKMapView). See an Objective-C example: http://stackoverflow.com/questions/13498636/how-to-add-touch-gesture-to-map-but-ignore-touches-on-pins-and-annotations –  Apr 22 '15 at 14:43

0 Answers0