目前我正在实现一项功能,用户可以手动更正 map 上的图钉。我已将annotationView 设置为annotationView.draggable = YES;
并且我还实现了委托(delegate)方法来接收新坐标。但是我现在如何告诉mapView拖动操作现在应该停止并且图钉在 map 上获得其固定位置,即使 map 随后被移动。
当前的行为是,将图钉拖动到新位置后,如果我随后移动 map ,图钉的固定位置仅在设备屏幕上,但不在 map 上。
感谢您的帮助:)。
代表:
- (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);
}
}
最佳答案
更新:
好的,已修复:
- (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;
}
}
现在我只需要保留新的坐标就可以了.. - 也许我会为各州添加一些自定义动画..:
When the drag state changes to MKAnnotationViewDragStateStarting, set the state to MKAnnotationViewDragStateDragging. If you perform an animation to indicate the beginning of a drag, and the animated parameter is YES, perform that animation before changing the state.
When the state changes to either MKAnnotationViewDragStateCanceling or MKAnnotationViewDragStateEnding, set the state to MKAnnotationViewDragStateNone. If you perform an animation at the end of a drag, and the animated parameter is YES, you should perform that animation before changing the state.
关于ios - 可拖动图钉在 map 上没有固定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22073519/