Is there a way to prevent an annotation in a MKMapView instance from being enabled. In other words, when the user taps the red pin on the map, is there a way to prevent it from highlighting the pin. Right now the pin turns dark when touched...
Edit: I'm using the following code to return the MKPinAnnotationView
// To future MKMapView users - Don't forget to set _mapView's delegate
_mapView.delegate = self;
_annotation = [[MKPointAnnotation alloc] init];
_annotation.coordinate = myLocation;
[_mapView addAnnotation:_annotation];
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:@"id"];
pin.enabled = NO;
return pin;
}
Set enabled
to NO
on your MKPinAnnotationView
, which you return from your -mapView:viewForAnnotation:
delegate method (if you haven't implemented it, do it).
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *annotationIdentifier = @"Annotation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
}
else {
annotationView.annotation = annotation;
}
annotationView.enabled = NO;
return annotationView;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.