Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preventing selection on MKPointAnnotation

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;
}
like image 881
Apollo Avatar asked Sep 13 '25 04:09

Apollo


1 Answers

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;
}
like image 165
Stanislav Yaglo Avatar answered Sep 15 '25 17:09

Stanislav Yaglo