【问题标题】:iOS Mapkit - Annotations disappear on map scroll/zoomiOS Mapkit - 注释在地图滚动/缩放时消失
【发布时间】:2013-05-01 23:54:57
【问题描述】:

在初始加载时,注释显示得很好。但是如果我滚动地图,它们都会消失,并且代码只针对用户位置调用,而不是 viewForAnnotation 委托方法中的其他注释。

绘制图钉

-(void)viewDidLoad{
     ...Download Coordinates and Data from Web here...
     [self.mapView addAnnotation:pin];
}

委托方法

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    //Player's Pin
    if([annotation class] == MKUserLocation.class) {
        return nil;
    }

    //Cluster Pin
    if([annotation isKindOfClass:[REVClusterPin class]]){
        REVClusterPin *pin = (REVClusterPin *)annotation;
        if( [pin nodeCount] > 0 ){
            pin.title = @"___";

            MKAnnotationView *annotationView  = (REVClusterAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];

            if( !annotationView ){
                annotationView = (REVClusterAnnotationView*)
                [[REVClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"cluster"];
            }

            annotationView.image = [UIImage imageNamed:@"cluster.png"];

            [(REVClusterAnnotationView*)annotationView setClusterText:
             [NSString stringWithFormat:@"%i",[pin nodeCount]]];

            annotationView.canShowCallout = NO;
            return annotationView;
        }
    }
    //Player Pin
    if([annotation isKindOfClass:[ZEPointAnnotation class]]){
        ZEPointAnnotation *pin = (ZEPointAnnotation *)annotation;
        MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
        if(!annotationView){
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
        }
        annotationView.canShowCallout = YES;
        annotationView.draggable = NO;

        ...Create Pin Data Here...

        return annotationView;
    }
    return nil;
}

【问题讨论】:

  • 尽管有以下两个观察结果,我仍然想知道问题是否出在其他地方。尝试暂时注释掉这个viewForAnnotation 方法。用户位置信标现在可以工作了吗?
  • 如果没有别的,你应该有if([annotation isKindOfClass:[MKUserLocation class]])。您真的不应该使用相等运算符测试class,尤其是因为您不确定iOS 可能不会在后台进行某些子类化。我不认为这是问题所在(因为它应该属于最终的return nil;,而只是一个观察。
  • 顺便说一句,如果dequeueReusableAnnotationViewWithIdentifier 曾经成功返回以前发布的MKAnnotationView,您是否设置过annotation 属性?就个人而言,我建议在那个if (!annotationView)else 子句中设置annotationView.annotation = annotation;
  • @Rob 我注释掉了 viewForAnnotation 并用默认的红色引脚映射了注释。但是当滚动/缩放地图时它们仍然全部消失(并且用户位置“重新动画化”)。我确实更新了 isKindOfClass 检查,谢谢。最后,通过调用 dequeReausable.. 它将在第一次加载时返回 nil。然后在该语句中创建 annotationView。之后,它将返回已经创建的注释......除非我误解了什么?
  • 哦,还是有同样的问题!好郁闷……

标签: ios annotations hide mapkit


【解决方案1】:

删除动画。这将解决您的问题

【讨论】:

    猜你喜欢
    • 2021-05-03
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-10
    相关资源
    最近更新 更多