【问题标题】:Add an image to MKPointAnnotation without changing User Location image在不更改用户位置图像的情况下将图像添加到 MKPointAnnotation
【发布时间】:2017-09-26 06:43:56
【问题描述】:

我正在使用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?

【问题讨论】:

    标签: ios objective-c mkmapview mkmapviewdelegate mkpointannotation


    【解决方案1】:

    在 MKMapViewDelegate 的 viewForAnnotation: 方法中添加这段代码

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

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2020-08-09
      • 2015-07-06
      • 1970-01-01
      • 2018-05-26
      • 2010-12-12
      • 1970-01-01
      • 2016-10-07
      • 2015-09-17
      相关资源
      最近更新 更多