目前,我正在实现一个功能,用户可以手动纠正地图上的一个引脚。我已经将annotationView设置为annotationView.draggable = YES;
,并且还实现了委托方法来接收新的坐标。但是,现在我如何告诉mapView,拖动操作现在应该停止,并且引脚在地图上得到固定位置,即使地图被移动了。
当前的行为是,在把引脚拖到一个新的位置后,如果我然后移动地图,引脚的固定位置只是在设备屏幕上,而不是在地图上。
非常感谢:)。
代表:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding)
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
}
}
发布于 2014-02-27 08:03:10
更新:
好的,修好了:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateStarting)
{
annotationView.dragState = MKAnnotationViewDragStateDragging;
}
else if (newState == MKAnnotationViewDragStateEnding || newState == MKAnnotationViewDragStateCanceling)
{
annotationView.dragState = MKAnnotationViewDragStateNone;
}
}
现在我必须坚持新的坐标,我很好.-也许我会为美国添加一些自定义动画..:
当拖动状态更改为MKAnnotationViewDragStateStarting时,将状态设置为MKAnnotationViewDragStateDragging。如果执行动画以指示拖动的开始,且动画参数为“是”,则在更改状态之前执行该动画。 当状态更改为MKAnnotationViewDragStateCanceling或MKAnnotationViewDragStateEnding时,将状态设置为MKAnnotationViewDragStateNone。如果在拖动结束时执行动画,且动画参数为“是”,则应在更改状态之前执行该动画。
https://stackoverflow.com/questions/22073519
复制