Ios 7 MKMapView draggable annotation changes its position when scrolling a map

I upgrade my application (MyWorld) to iOS 7. One of the features of the application is that you can drag a pin on the map. It seems to be broken in iOS7.

Steps to recreate the problem:

  • Adding annotations to the map: - works great
  • Moving annotations (drag and drop) works fine
  • Scrolling map: problem

Whenever I look at the annotation of the map view, it moves with the map. Doesn't it seem to be attached to the right kind or layer? If the pin pin is not being dragged, it seems to work fine and the annotation stays in a certain position. I wonder if this is a mistake on my side or a known problem?

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

+4
source share
2 answers

This is from the MKAnnotationView class reference for the MKAnnotationViewDragStateNone constant:

MKAnnotationViewDragStateNone

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

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

For instance:

- (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]; } } 
+17
source

I had the same problem and decided to add "setDragState" to the MKAnnotationView class.

This is an old solution, but it worked with me (iOS7): fooobar.com/questions/551952 / ...

0
source

All Articles