ios – 拖动我的MKAnnotationView后拖动地图不会随之移动MKAnnotationView

前端之家收集整理的这篇文章主要介绍了ios – 拖动我的MKAnnotationView后拖动地图不会随之移动MKAnnotationView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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;
}@H_403_7@

解决方法

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

This是一个旧的解决方案,但它对我有用(iOS8).

原文链接:https://www.f2er.com/iOS/335292.html

猜你在找的iOS相关文章