可拖动Pin在地图上没有固定位置

时间:2014-02-27 15:50:32

标签: ios ios7 mkmapview mkannotationview

目前我正在实施一项功能,用户可以手动修正地图上的图钉。我已将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);
    }
}

1 个答案:

答案 0 :(得分:4)

更新:

好的,修好了:

- (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。如果你执行   动画以指示拖动的开始和动画   参数为YES,在更改状态之前执行该动画。

     

当状态更改为MKAnnotationViewDragStateCanceling或   MKAnnotationViewDragStateEnding,将状态设置为   MKAnnotationViewDragStateNone。如果你最后执行动画   拖动,动画参数为YES,您应该执行该操作   改变状态前的动画。

相关问题