我正在使用this代码将图片添加到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;
}
但它也显示了用户位置的自定义图像。用户位置的圆形波动也消失了。
有没有办法在不改变用户位置图像和动画的情况下将图像添加到MKPointAnnotation?
答案 0 :(得分:1)
在MKMapViewDelegate的viewForAnnotation:方法中添加此代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == mapView.userLocation) return nil;