【问题标题】:iPhone MapKit: Annotation images get reset back to pinsiPhone MapKit:注释图像被重置回引脚
【发布时间】:2011-01-06 11:04:32
【问题描述】:

我正在向 MapView 添加几个注释并使用自定义图像而不是默认图钉。我正在使用viewForAnnotation 委托方法来设置自定义图像,如下所示:

view.image = [UIImage imageNamed:@"placemark.png"];

我也试过了:

[(MKPinAnnotationView *)view setImage:[UIImage imageNamed:@"placemark.png"]];

现在,这两个都很好地设置了图像。但是,当点击注释或mapType 更改为 Satellite 或 Hybrid 时,它会重置回红色 pin 图像。我错过了什么?

【问题讨论】:

    标签: iphone mapkit mkmapview mkpinannotationview


    【解决方案1】:

    不要使用 MKPinAnnotationView - 只需使用 MKAnnotationView。

    【讨论】:

      【解决方案2】:

      我想我明白了。我最终不得不继承 MKAnnotationView。

      【讨论】:

        【解决方案3】:
        MKAnnotationView* pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
        
        pinView.animatesDrop=YES;
        pinView.canShowCallout=YES;
        pinView.image=[UIImage imageNamed:@"userMain.png"];
        

        不要给MKPinAnnotation 它采用默认引脚注释。只使用MKAnnotationView 对象,不要使用:

        pinView.animatesDrop=YES;
        

        【讨论】:

        • 我认为编辑是为了符合区分代码和叙述的标准。注意你的代码是如何使用 Courier 字体的,而你的叙述不是。
        猜你喜欢
        • 1970-01-01
        • 2012-12-20
        • 1970-01-01
        • 2013-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多