(iPhone)如何在使用OS 4.0 MapKit时实现可拖动的标记?

10

有人能够提供在使用MapKit框架下实现可拖动固定点的样例代码/指导吗?

2个回答

14

没问题,伙计(是的,我在和自己说话),

在你的自定义注释中添加:

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate; 

这满足了实现setCoordinate的要求,如http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView/draggable所述。

在您的MapView代理中添加:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
{
//..Whatever you want to happen when the dragging starts or stops
}

并且在您的AnnotationView中将draggable设置为true,例如:

customAnnotationView.draggable      = YES;

我认为这就是我所做的一切来使它正常工作。如果你遇到问题,请告诉我。


我正在使用书籍“More iPhone Development”中的自定义注释类“MapLocation” - 这是一个普通的自定义注释类。我添加了,assign到现有属性,使其像上面那样,但拖动回调从未被调用。在viewForAnnotation中,我将注释强制转换为MapLocation并获取其视图并设置draggable = YES。我只是为了测试而这样做,我可能会选择OS3支持。但是你有什么想法可能缺失了什么? - Henrik Erlandsson
Tristan,你能否分享一下你用来让它正常工作的代码?我已经尽我所能了,但出于某种原因,我无法使引脚移动,我尝试了所有可以找到的教程(包括下面的评论)。谢谢! - Kinetic Stack

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接