Search code examples
iosmkmapviewmkannotationmkannotationview

Custom MKAnnotationView, how to prevent selection when shadow touched


I have got a MapView with some custom MKAnnotation, MKAnnotationView which I use to create nice custom callout. Anyway, for my main Annotation Pin, I use some nice image of pins with a pre-rendered shadow on their left.

However, I would like the annotation not to get selected when the user touch its shadow. Because when their are a lot of them, the shadow of one can overlap another, and the wrong one gets selected because the shadow gets touched.

I have tried to use a separate image for the shadow and put it in a UIImageView inside the MKAnnotationView but it does not change anything, even if I put enableUserInteraction = NO.

any idea?


Solution

  • Make your MKAnnotationView the size of the image excluding the shadow. Change it's frame so that it encompasses the part you want it to receive touch. The shadow should exceed this frame, but shouldn't be cut off.