MapView Annotation不拖动

mle*_*s54 4 iphone annotations mapkit

我试图在地图视图中实现一个可拖动的"pin"(实际上是一个自定义图标).这是我的委托代码:

  -(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKAnnotationView *aView;

    aView=(MKAnnotationView *) [mvMap dequeueReusableAnnotationViewWithIdentifier:annotation.title];
    if (aView==nil) 
        aView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotation.title] autorelease];
    else
        aView.annotation=annotation;
    [aView setImage:[UIImage imageNamed:selIcon]];
    aView.canShowCallout=TRUE;
    [aView setDraggable:YES];
    return aView;
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { 
    MKAnnotationView *aV; 
    for (aV in views) {
        CGRect endFrame = aV.frame;

        int xDelta=0;
        xDelta=sIcons.selectedSegmentIndex*61+22;
        aV.frame = CGRectMake(aV.frame.origin.x-145+xDelta, aV.frame.origin.y - 150.0, aV.frame.size.width, aV.frame.size.height);

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.7];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [aV setFrame:endFrame];
        [UIView commitAnimations];
    }
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {
    if (oldState == MKAnnotationViewDragStateDragging) {
        addAnnotation *annotation = (addAnnotation *)view.annotation;
        annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];
    }
    if (newState == MKAnnotationViewDragStateEnding) {
        CLLocationCoordinate2D droppedAt = view.annotation.coordinate;
        NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是永远不会调用didChangeDragState(我在例程中设置了断点以确定).其他一切都很好.我的图标动画进入视图等.当我点击图标并按住我的手指时,图标保持原位(地图不会移动,这使我认为我实际上已经点击了图标).我错过了某种初始化吗?

mle*_*s54 13

得到它了!问题出在我的自定义注释类的接口文件中.违规行如下:

@property (nonatomic,readonly) CLLocationCoordinate2D   coordinate;
Run Code Online (Sandbox Code Playgroud)

它必须阅读:

@property (nonatomic,readwrite,assign) CLLocationCoordinate2D   coordinate;
Run Code Online (Sandbox Code Playgroud)

我想它必须具有读/写功能.