问题描述
MKPinAnnotationView不允许您将自定义图像用作pin并同时启用拖动,因为一旦开始拖动,图像就会更改回默认图钉。因此我使用MKAnnotationView而不是MKPinAnnotationView。
MKPinAnnotationView does not allow you to use a custom image as 'pin' and enable dragging at the same time, because the image will change back to the default pin as soon as you start dragging. Therefore I use an MKAnnotationView instead of an MKPinAnnotationView.
虽然使用MKAnnotationView而不是MKPinAnnotationView确保您的自定义图像显示为pin,但它不支持drag& amp ;使用默认引脚删除动画。
While using MKAnnotationView instead of MKPinAnnotationView does keep your custom image shown as your 'pin' it doesn't support the drag & drop animation that you get with the default pin.
无论如何,我的问题是,在我将自定义MKAnnotationView拖到地图上的新点然后移动地图本身后,MKAnnotationView不再随地图一起移动。
Anyway, my issue is that after I drag my custom MKAnnotationView to a new point on the map and then move the map itself the MKAnnotationView does not move with the map anymore.
-(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类。
I had the same problem and I solved it adding "setDragState" to my MKAnnotationView class.
是一个旧的解决方案,但它对我有用(iOS8)。
This is an old solution but it worked to me (iOS8).
这篇关于拖动MKAnnotationView后拖动地图不会移动MKAnnotationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!