Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios 7 MKMapView draggable annotation change it's position when map is scrolled

I am updating my app (MyWorld) to iOS 7. One of the features of the app is that you can drag pin on the map view. It seems to be broken in iOS7.

Steps to recreate the problem:

  • Adding Annotation to the map: - works fine
  • Moving Annotation (Dragging) works fine
  • Scrolling the map: Problem

Whenever I scroll the map view annotation is moved with the map. It seems like it's not attached to the right view or layer?? If the pin is not dragged map view seems to work fine and annotation stays in defined position. I wonder if this is a mistake on my side or a known issue?

I created a dummy MapViewTest project that ilusstrates the problem on github: https://github.com/DJMobileInc/MapViewTest

like image 801
Janusz Chudzynski Avatar asked Sep 24 '13 04:09

Janusz Chudzynski


1 Answers

This is from the MKAnnotationView Class Reference, for the MKAnnotationViewDragStateNone constant:

MKAnnotationViewDragStateNone

The view is not involved in a drag operation. The annotation view is responsible for returning itself to this state when a drag ends or is canceled.

To fix the problem, your map view delegate will need to set the annotation view's dragState back to MKAnnotationViewDragStateNone when ever the annotation ends or cancels its drag operation.

For example:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView
                                 didChangeDragState:(MKAnnotationViewDragState)newState
                                       fromOldState:(MKAnnotationViewDragState)oldState
{
    if (newState == MKAnnotationViewDragStateEnding) {
        // custom code when drag ends...

        // tell the annotation view that the drag is done
        [annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
    }

    else if (newState == MKAnnotationViewDragStateCanceling) {
        // custom code when drag canceled...

        // tell the annotation view that the drag is done
        [annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
    }
}
like image 174
glenn Avatar answered Nov 09 '22 03:11

glenn