Search code examples
ios7mapkitmkannotationview

MKAnnotationViewDragStateEnding never sent


I'm trying to drag an MKAnnotation from a Track (List of Coordinates)

The performance is not the expected against previous experiences with iOS6, now when the Annotation moves up moves down until you have the pressed the Point ... for sure I'm doing something wrong :S

Anyway, I wan't to expect for a MKAnnotationViewDragStateEnding to update the MKPolygon of the track, but the state never arrives.

I had my own MKAnnotation class following the Apple guidelines

@interface SMAnnotation : NSObject <MKAnnotation>
{ 
   CLLocationCoordinate2D coordinate;    
} 
@property (nonatomic,readonly) CLLocationCoordinate2D   coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D)coord;
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;

And I already defined the draggable on the MKMapView's UIViewController

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"myPin"];
    pin.animatesDrop = YES;
    pin.draggable = YES;
    pin.enabled = YES;
    pin.pinColor = MKPinAnnotationColorGreen;

    return pin;
}

(I removed the reuse code after read some previous solutions here without succeed)

I include the method to evaluate the performance of the controller:

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

A sample of the log is the next one:

2014-08-04 18:08:24.030 XXX[8462:60b] Received an Starting State
2014-08-04 18:08:24.031 XXX[8462:60b] starting At at 41.778202,3.029813
2014-08-04 18:08:24.031 XXX[8462:60b] Received an Dragging State 
2014-08-04 18:08:24.565 XXX[8462:60b] Received an None State
2014-08-04 18:08:28.333 XXX[8462:60b] Received an Starting State
2014-08-04 18:08:28.334 XXX[8462:60b] starting At at 41.778204,3.030127
2014-08-04 18:08:28.334 XXX[8462:60b] Received an Dragging State
2014-08-04 18:08:28.866 XXX[8462:60b] Received an None State
2014-08-04 18:08:39.920 XXX[8462:60b] Received an Starting State
2014-08-04 18:08:39.920 XXX[8462:60b] starting At at 41.778165,3.030228
2014-08-04 18:08:39.920 XXX[8462:60b] Received an Dragging State
2014-08-04 18:08:40.454 XXX[8462:60b] Received an None State

After that I also created an Customized MKAnnotationView: MKPinAnnotationView

- (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated
{
    [super setDragState:newDragState animated:animated];

    switch (newDragState) {
        case MKAnnotationViewDragStateNone:
        {
            NSLog(@"AV::Received an None State");
            break;
        }
...
    }
}

The MKAnnotationViewDragStateEnding is received on the MKAnnotationView but not propagated to the MKMapViewDelegate ...

Any suggestion?

Thanks!!!


Solution

  • After evaluate some workarounds I decide to create a MKMapView subclass to guarantee the order of the MKAnnotations.

    The MKMapView provides by default a NSSet, but for a track the order is relevant.

    Using this workaround I don't need to expect for the drag report to get the new coordinate and redraw the MKPolyline, I could just use the NSArray on the MKMapView subclass to do that.

    Regards