开发者

MKMapView disable pin drags

开发者 https://www.devze.com 2023-02-28 16:26 出处:网络
I\'m loading data from an array and dropping pins for entries with a specified location. I\'m doing this in my viewWillAppear method.

I'm loading data from an array and dropping pins for entries with a specified location. I'm doing this in my viewWillAppear method.

I add the pins by initializing annotations for the said entries and then adding them via

[userLocation addAnnotations: annotations];

However, I have noticed that I am still able to drag the pins around. Is there any way of preventing the user from dragging the 开发者_Python百科pins from their predefined position? Thanks for your help.

viewWillAppear:

for(d=0;d<[eventArray count];d++){
    Entry *element=[eventArray objectAtIndex:d];
    float lon=[tmp.lon floatValue];
    float lat=[tmp.lat floatValue];
    if(lon!=0 && lat!=0){
        CLLocationCoordinate2D coord = {lat, lon};
        MyAnnotation *annotation=[[MyAnnotation alloc]initWithCoordinate:coord title:@"A  pin"];

        [userLocation addAnnotations: annotations];
    }
}

And then as suggested:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

MyAnnotation *annotationView = (MyAnnotation *)[self.userLocation dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if (annotationView == nil) {
    annotationView = [[[DDAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
 //   annotationView.rightCalloutAccessoryView = nil;
}
annotationView.draggable=NO;
return annotationView;

}


you mean, you are able to drag'n'drop the pins around? this should only be possible, when you enabled this before with annotationView.draggable = YES;.

0

精彩评论

暂无评论...
验证码 换一张
取 消