ios – 拖动我的MKAnnotationView后拖动地图不会随之移动MKAnnotationView
2020年01月07日
作者:佚名
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).
以上是来客网为你收集整理的ios – 拖动我的MKAnnotationView后拖动地图不会随之移动MKAnnotationView全部内容,希望文章能够帮你解决ios – 拖动我的MKAnnotationView后拖动地图不会随之移动MKAnnotationView所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。