MKMapView 禁用图钉拖动
我正在从数组加载数据,并为具有指定位置的条目放置引脚。我在 viewWillAppear 方法中执行此操作。
我通过初始化上述条目的注释来添加引脚,然后通过添加它们。
[userLocation addAnnotations: annotations];
但是,我注意到我仍然可以拖动引脚。有什么方法可以防止用户将引脚从预定义位置拖动?感谢您的帮助。
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];
}
}
然后按照建议:
-(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;
}
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 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是,你可以拖放引脚吗?只有当您之前使用
annotationView.draggable = YES; 启用此功能时,这才可能实现。
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;
.