我有一个我添加引脚的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;
}
}
答案 0 :(得分:0)
修正了我自己的问题。我将MKMapView子类化为GenericMapView,以便我的代码更清晰(从实际的View Controller中删除showsUserLocation,zoom / scroll / rotateEnabled,showsCompass等),但这意味着委托没有正确设置而且viewForAnnotation不是要求重新加载引脚。