小编gun*_*ner的帖子

拖动注释时的回调

我可以拖动我的注释,当我放下它时,我可以读取位置.但是,我需要不断更新我的标题与我拖动的位置.我尝试添加UIPanGestureRecognizer但是在拖动注释时不起作用.在拖动注释时,我应该使用什么方法来不断回调我的代码?

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
                didChangeDragState:(MKAnnotationViewDragState)newState
                fromOldState:(MKAnnotationViewDragState)oldState {

CLLocationCoordinate2D annoCoord = view.annotation.coordinate;

switch (newState) {
    case MKAnnotationViewDragStateStarting:
        NSLog(@"Start dragging annotation");
        break;

    case MKAnnotationViewDragStateDragging:
        NSLog(@"Dragging annotation");
        break;

    case MKAnnotationViewDragStateEnding:
        [view setDragState:MKAnnotationViewDragStateNone]; // must be here! else multiple calls
        NSLog(@"Ending dragging annotation at %f : %f", annoCoord.latitude, annoCoord.longitude);
        break;

    case MKAnnotationViewDragStateCanceling:
        NSLog(@"Cancel dragging annotation");
        break;

    case MKAnnotationViewDragStateNone:
        NSLog(@"None dragging annotation");
        break;
    default:
        break;
    }

}
Run Code Online (Sandbox Code Playgroud)

我只在州开始时获得回调,而不是在拖动期间.

任何帮助将非常感激.

干杯,tord

annotations drag-and-drop ios

3
推荐指数
1
解决办法
538
查看次数

标签 统计

annotations ×1

drag-and-drop ×1

ios ×1