我已經編寫了一些代碼,用於在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