拖动我的MKAnnotationView后拖动地图不会移动MKAnnotationView

MKPinAnnotationView不允许您使用自定义图像作为“插针”并同时启用拖动,因为只要开始拖动,图像就会变回默认的插针。 因此,我使用MKAnnotationView而不是MKPinAnnotationView。

虽然使用MKAnnotationView而不是MKPinAnnotationView会使您的自定义图像显示为“引脚”,但不支持使用默认引脚获取的拖放animation。

无论如何,我的问题是,我将我的自定义MKAnnotationView拖动到地图上的新点后,然后移动地图本身,MKAnnotationView不会随地图一起移动。

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { static NSString *defaultID = @"myLocation"; if([self.annotation isKindOfClass:[PinAnnotation class]]) { //Try to get an unused annotation, similar to uitableviewcells MKAnnotationView *annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultID]; //If one isn't available, create a new one if(!annotationView) { annotationView = [[MKAnnotationView alloc] initWithAnnotation:self.annotation reuseIdentifier:defaultID]; annotationView.canShowCallout = YES; annotationView.draggable = YES; annotationView.enabled = YES; } UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 32, 32)]; imgView.image = self.passableTag.image; annotationView.leftCalloutAccessoryView = imgView; annotationView.image = [UIImage imageNamed:[Constants tagIconImageNameForTagType:self.passableTag.type]]; return annotationView; } return nil; } 

我有同样的问题,我解决了它添加“setDragState”到我的MKAnnotationView类。

这是一个古老的解决scheme,但它对我(iOS8)。

只需在结束拖动后将annotationView.dragState设置为MKAnnotationViewDragStateNone即可:

  - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if ([view.annotation isKindOfClass:[PinAnnotation class]]) { if (newState == MKAnnotationViewDragStateEnding) { view.dragState = MKAnnotationViewDragStateNone; } } } 

不要重复使用MKAnnotationView,它会工作。