我已经编写了一些代码,用于在mapview中显示带有自定义图像的注释。ios-mapkit,自定义图像注释的奇怪行为
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation {
if ([annotation isKindOfClass:[Station class]]) {
Station *current = (Station *)annotation;
MKPinAnnotationView *customPinview = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
if([[current type] compare:FONTANELLA]==NSOrderedSame)
customPinview.pinColor = MKPinAnnotationColorPurple;
else{
int test=current.bici;
if(test==0)
customPinview.image = [UIImage imageNamed:@"bicimir.png"];
else if(test<4)
customPinview.image = [UIImage imageNamed:@"bicimi.png"];
else if(test>=4)
customPinview.image = [UIImage imageNamed:@"bicimig.png"];
}
customPinview.animatesDrop = NO;
customPinview.canShowCallout = YES;
return customPinview;
}
else{
NSString *[email protected]"MyLocation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
return annotationView;
}
}
的问题是一个奇怪的现象,当我长点击地图上的自定义注释: 的 当他们放在地图我MapView的委托实现此方法自定义注释图像变化并显示默认的红色针脚。
为什么会这样?我怎样才能避免它?
感谢您的答复!这非常有用 – Matteo