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;
}

解决方法

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

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...