問題描述
我正在注釋我的地圖并設(shè)置圖像就好了,但是當(dāng)我點(diǎn)擊 MapView 上的注釋時(shí),圖像會(huì)從我的自定義圖像返回到紅色圖釘.這是為什么呢?
I am annotating my map and setting an image just fine, but when I tap the annotation on the MapView, the image goes from my custom image back to the red pin. Why is this?
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
}
annotation.image = [UIImage imageNamed:@"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}
我的代碼看起來與一些不會(huì)產(chǎn)生此問題的示例代碼相同.
My code looks identical to some sample code that does not produce this problem.
推薦答案
在這里回答我自己的問題,以防其他人有同樣的問題.請(qǐng)注意,我正在使用MKPinAnnotationView" - 它應(yīng)該更改為MKAnnotationView"并且一切正常.
Answering my own question here, just in case others have the same issue. Notice that I am using "MKPinAnnotationView" - it should be changed to "MKAnnotationView" and everything works.
固定代碼:
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKAnnotationView *annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
}
annotation.image = [UIImage imageNamed:@"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}
這篇關(guān)于為什么自定義的 MKMapView 注釋圖像在觸摸時(shí)會(huì)消失?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!