ios - 可拖动图钉在 map 上没有固定位置

标签 ios ios7 mkmapview mkannotationview

目前我正在实现一项功能,用户可以手动更正 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/

相关文章:

ios - 使用 Lottie 自定义 UIRefreshControl

ios - EAS 构建 - rsync 错误 : some files could not be transferred (code 23) error

ios - 如何在加载 map 时直接显示多个注释的标题

ios - "NSAttributedString initWithData: options: documentAttribute: error:"未按预期工作

ios - 从 Firebase 数据库在 MKMapView 上放置多个标记

ios - 无法在 MKMapView 中显示多个注释图钉

iOS 9 - Xcode : "Follows Readable Width" programmatically

ios - 追加从不同 View Controller 创建的新对象执行segue

objective-c - 如何通过摘要身份验证使用 AFNetworking 2

ios - 如何使用新的 iOS 7 API 获取自动换行信息?