0

我使用this代码将图像添加到MKPointAnnotation。在不更改用户位置图像的情况下将图像添加到MKPointAnnotation

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString *SFAnnotationIdentifier = @"SFAnnotationIdentifier"; 
    MKPinAnnotationView *pinView = 
    (MKPinAnnotationView *)[_routeMap dequeueReusableAnnotationViewWithIdentifier:SFAnnotationIdentifier]; 
    if (!pinView) 
    { 
     MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation 
                     reuseIdentifier:SFAnnotationIdentifier]; 
     UIImage *flagImage = [UIImage imageNamed:@"BikeIconMap"]; 
     // You may need to resize the image here. 
     annotationView.image = flagImage; 
     return annotationView; 
    } 
    else 
    { 
     pinView.annotation = annotation; 
    } 
    return pinView; 
} 

但它也显示用户位置的自定义图像。用户位置的圆形波动画也消失了。

enter image description hereenter image description here

有没有一种方法来添加图片到MKPointAnnotation不改变用户位置的图像和动画?

回答

1

在viewForAnnotation添加以下代码:方法MKMapViewDelegate

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if (annotation == mapView.userLocation) return nil; 
相关问题