【问题标题】:MKMapView with custom pins return to red standard pins on reload带有自定义引脚的 MKMapView 在重新加载时返回到红色标准引脚
【发布时间】:2016-09-02 11:57:15
【问题描述】:

我有一个添加图钉的 MKMapView。它们正确加载了相关图形,但如果我放大和缩小它们,它们会松开图形并变成标准的红色图钉,唯一的自定义是图钉名称(甚至我的披露指示器也会消失)。

到目前为止,我已经尝试过修复它: 尝试了 png,在更快的设备上检查,将所有内容从 MKPinAnnotation 更改为 MKAnnotation,返回到正常的 MKAnnotation 而不是我的自定义 CBAnnotation,用于加载自定义图钉的各种示例代码,降低地图覆盖的质量,以防加载问题但仍然是一个问题.

- (void)addPins {
    mapPinsArray = [[NSMutableArray alloc] init];

    for (MapPoint *mappoint in mapPointsArray) {
        CBAnnotation *annotation = [[CBAnnotation alloc] init];
        annotation.coordinate = CLLocationCoordinate2DMake(mappoint.loclat, mappoint.loclong);
        annotation.title = mappoint.stopAreaName;
        annotation.mapPoint = mappoint;
        [mapPinsArray addObject:annotation];
        [self.myMapView addAnnotation:annotation];
    }
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(CBAnnotation *)annotation {

    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        //do nothing
        return nil;
    } else {
        MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"trailPoint"];
        annotationView.canShowCallout = YES;

        ButtonWithData *accessoryViewButton = [[ButtonWithData alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        [accessoryViewButton setBackgroundImage:[UIImage imageNamed:@"right_arrow"] forState:UIControlStateNormal];
        accessoryViewButton.buttonData = annotation.mapPoint;
        [accessoryViewButton addTarget:self action:@selector(disclosureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        annotationView.rightCalloutAccessoryView = accessoryViewButton;

        if (![[NSUserDefaults standardUserDefaults] boolForKey:annotation.mapPoint.stopAnimalName]) {
            annotationView.image = [annotation.mapPoint lockedPinImage];
        } else {
            annotationView.image = [annotation.mapPoint unlockedPinImage];
        }

        return annotationView;
    }
}

【问题讨论】:

    标签: ios xcode mkmapview mkannotation mkannotationview


    【解决方案1】:

    解决了我自己的问题。我将 MKMapView 子类化为 GenericMapView,以便我的代码更清晰(从实际的 View Controller 中删除 showsUserLocation、zoom/scroll/rotateEnabled、showsCompass 等),但这意味着委托设置不正确,并且未在引脚上调用 viewForAnnotation重新加载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-05
      • 2015-01-05
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多