I have a custom MKAnnotationView
that I am loading from an XIB
. When I first load the mapview, I have several standard MKAnnotationView
.
When a user selects one, the custom MKAnnotationView
is presented. I would like for the user to be able to tap anywhere inside the custom annotation view to present a new view controller.
What I've tried (all of these were suggestions I found here on StackOverflow):
- Overriding hit test is the custom MKAnnotationView class. The issue here is that CGPoint would return as nil most of the time. (How do I make a MKAnnotationView touch sensitive?)
- Adding a tap gesture to a UIButton and adding that button to the custom annotation view in the viewForAnnotation delegate method. (How to get click event from a button added over MKAnnotationView). This never really worked and it didn't make much sense to me. Adding a tap gesture to a button seems redundant.
- Adding KVO to the annotation view. (http://www.jakeri.net/2009/12/custom-callout-bubble-in-mkmapview-final-solution/). This caused an issue because the annotationView that was added to the map seemed to get deallocated before sending the notification.
- Adding a clear button in the XIB that is the size of the custom view and adding a target/selector to it. I also make sure to bring it to the front of the parent view.
What is strange is that if I drag the map while the annotation is present, the button works fine. The issue only shows up when I first show the custom view.
Any ideas would be appreciated.