MKPinAnnotationView不允许您将自定义图像用作’pin’并同时启用拖动,因为一旦开始拖动,图像就会变回默认图像.因此我使用MKAnnotationView而不是MKPinAnnotationView.
虽然使用MKAnnotationView而不是MKPinAnnotationView确实将您的自定义图像显示为“pin”,但它不支持drag&使用默认引脚删除动画.@H_404_3@
无论如何,我的问题是,在我将自定义MKAnnotationView拖到地图上的新点然后移动地图本身之后,MKAnnotationView不再随地图一起移动.@H_404_3@
-(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; }