MKPinAnnotationView不允许您将自定义图像用作’pin’并同时启用拖动,因为一旦开始拖动,图像就会变回默认图像.因此我使用MKAnnotationView而不是MKPinAnnotationView.
虽然使用MKAnnotationView而不是MKPinAnnotationView确实将您的自定义图像显示为“pin”,但它不支持drag&使用默认引脚删除动画.
无论如何,我的问题是,在我将自定义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类.
This是一个旧的解决方案,但它对我有用(iOS8).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。