MKAnnotationView自定义图像不显示

问题描述:

我想在地图上添加自定义图像,而不是常规图钉。但它仍然是一个红色的针......我错过了什么?MKAnnotationView自定义图像不显示

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKPinAnnotationView *annView = [[MKPinAnnotationView alloc]  initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 
    annView.animatesDrop = TRUE; 
    annView.image = [UIImage imageNamed:@"CustomPin.png"]; 
    return annView; 
} 
+0

见http://*.com/questions/10501341/ mkpinannotationview-custom-image-is-replace-by-pin-with-animating-drop – Anna 2012-08-06 14:16:53

+0

你的代码工作,但缺少动画Drop。我加了pinView.animatesDrop = YES;但有一个错误 - 属性animatesDrop没有在MKAnnotationView上找到。所以,修复它:http://*.com/a/2087253/1341180 – Luda 2012-08-06 15:21:44

+0

如果你会把这个链接作为答案,我会检查它是正确的 – Luda 2012-08-06 15:22:39

MKMapView: Instead of Annotation Pin, a custom view

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKAnnotationView *pinView = nil; 
    if(annotation != mapView.userLocation) 
    { 
     static NSString *defaultPinID = @"com.invasivecode.pin"; 
     pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinView == nil) 
      pinView = [[MKAnnotationView alloc] 
             initWithAnnotation:annotation reuseIdentifier:defaultPinID]; 

     //pinView.pinColor = MKPinAnnotationColorGreen; 
     pinView.canShowCallout = YES; 
     //pinView.animatesDrop = YES; 
     pinView.image = [UIImage imageNamed:@"pinks.jpg"]; //as suggested by Squatch 
    } 
    else { 
     [mapView.userLocation setTitle:@"I am here"]; 
    } 
    return pinView; 
} 

我发现它有助于查看苹果文档并下载示例代码。

http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746

他们正在实施自己的地图自定义注释。

嗨只是删除您一行代码... annView.animatesDrop = TRUE;

次还代码 -

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKPinAnnotationView *annView = [[MKPinAnnotationView alloc]  initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 
    annView.image = [UIImage imageNamed:@"CustomPin.png"]; 
    return annView; 
}