可拖动的图钉在地图上没有固定位置 [英] Draggable Pin does not have a fixed position on map

查看:118
本文介绍了可拖动的图钉在地图上没有固定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在实现一项功能,用户可以在其中手动校正地图上的图钉.我已经将annotationView设置为annotationView.draggable = YES;,并且还实现了委托方法来接收新坐标.但是,现在我该如何告诉mapView,拖动动作应该立即停止并且即使在随后移动地图的情况下,图钉也会在地图上获得固定的位置.

Currently I am implementing a feature, where the user can correct manually a pin on the map. I have set the annotationView to annotationView.draggable = YES; and I have also implemented the delegate method to receive the new coordinates. But how can I now tell the mapView that the dragging action should stop now and the pin gets its fixed position on the map, even if the map is then moved.

当前行为是,将图钉拖动到新位置后,如果我再移动地图,则图钉仅在设备屏幕上而不是在地图上具有其固定位置.

The current behaviour is that after the dragging of the pin to a new position, if I then move the map, the pin has its fixed position just on the device screen but not on the map.

我们非常感谢您的帮助:).

Help is appreciated :).

委托:

- (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;
    }
}

现在,我只需要保留新坐标,就可以了.-也许我会为状态添加一些自定义动画..

Now I just have to persist the new coordinates and I am fine.. - maybe I will add some custom animations for the states..:

当拖动状态更改为MKAnnotationViewDragStateStarting时,设置 状态为MKAnnotationViewDragStateDragging.如果您执行 动画以指示拖动的开始,动画 参数为YES,请在更改状态之前执行该动画.

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.

当状态更改为MKAnnotationViewDragStateCanceling或 MKAnnotationViewDragStateEnding,将状态设置为 MKAnnotationViewDragStateNone.如果在最后执行动画 拖动,并且动画参数为YES,则应执行该操作 动画,然后再更改状态.

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.

这篇关于可拖动的图钉在地图上没有固定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆