How to detect touch annotation view event?
I have some Annotationview on map. I just wanna detect event that happen when user touc开发者_如何学运维h it. I figure out using observer, I add observer for each annotationview in viewForAnnotation delegate method. I thought it would work perfect, but something still wrong. "selected" attribute of annotationview change its value unexpectedly. Someone tell me how to solve this problem. Thanks!
You should see about the MKMapViewDelegate there is this method to implement in order to do that :
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
See the apple's doc http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html
You can add event handler to your custom annotation view:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.superview bringSubviewToFront:self];
[super touchesBegan:touches withEvent:event];
}
You can also use KVO as this method.
精彩评论