Search code examples
iphoneios4mkmapviewmkpinannotationview

How can drag MKPinAnnotationView pin only one tap?


i add MKPinAnnotationView and setDragAble. my code is here

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
    [annotationView setDraggable:YES];
    annotationView.pinColor = MKPinAnnotationColorPurple;
    return [annotationView autorelease];
}

ok i can drag pin.

but one problem is it's not just one tap. always need second tap.

when i first tap pin is selected but can't drag. when i tap again it's available drag.

what's wrong? i want just one tap drag like "Map.app"


Solution

  • Reslove this problem. ^^

    i think for drag pin, pin is already selected.

    so selected MKPinAnnotationView when it init.

    my new code.

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
        MKPinAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
        [annotationView setDraggable:YES];
        annotationView.pinColor = MKPinAnnotationColorPurple;
        [annotationView setSelected:YES animated:YES];
        return [annotationView autorelease];
    }