Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dragging annotation view causes multiple triggering of drag state delegate method

This one is a bit obscure.

This MKMapViewDelegate has a method which is supposed to tell you when you sart and finish dragging an annotation view. I have implemented like so:

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

    if (oldState == MKAnnotationViewDragStateStarting && newState == MKAnnotationViewDragStateEnding)
    {
        NSLog(@"Ending drag");
    }

    if (newState == MKAnnotationViewDragStateStarting)
    {
        NSLog(@"Beginning drag");
    }
}

This kind of works. However, when I stop dragging the annotation, and drag it again, then the above method is triggered twice, then 3 times etc. So the console displays:

Beginning drag
Ending drag

Beginning drag
Beginning drag
Ending drag
Ending drag

Beginning drag
Beginning drag
Beginning drag
Ending drag
Ending drag
Ending drag

Beginning drag
Beginning drag
Beginning drag
Beginning drag
Ending drag
Ending drag
Ending drag
Ending drag

Any ideas on what is causing this?

like image 990
cannyboy Avatar asked Dec 27 '22 18:12

cannyboy


1 Answers

I seemed to solve this by adding:

[annotationView setDragState:MKAnnotationViewDragStateNone];

in the 'ending drag' part of the if statement.

like image 61
cannyboy Avatar answered May 09 '23 06:05

cannyboy