ios - MapView 自定义 Pin 图问题

标签 ios mkmapview mkannotation mkpinannotationview

我已经更改了我的 MapView 图钉图像,但我遇到了这个问题,其中一些点不会更改图钉图像,而其中一些会发生变化。问题会出在哪里呢?我添加了一个示例。

我的代码:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;

MKAnnotationView *pinView = nil;


if(annotation != locationMap.userLocation)
{
    static NSString *defaultPinID = @"myPin";

    pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinAnnotation == nil )
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

    pinAnnotation.canShowCallout = YES;
    pinAnnotation.animatesDrop = YES;
    pinAnnotation.enabled = YES;
    //pinAnnotation.image = [UIImage imageNamed:@"pin.png"];

    pinView.image = [UIImage imageNamed:@"pin.png"];


    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinAnnotation.rightCalloutAccessoryView = infoButton;
    }
    return pinAnnotation;

    return pinView;

}

Add image that show the issue

最佳答案

使用常规 MKAnnotationView,而不是 MKPinAnnotationView 子类。即使您可以设置图像,但也不能保证它会粘住,因为它可以并且会再次将图钉图像设置回来。

关于ios - MapView 自定义 Pin 图问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18568118/

相关文章:

ios - VoIP 推送通知在装有 iOS 10.3 的 iPhone 7 上崩溃

iphone - 更改 MKMapView 中当前位置的图像

ios - 子类化 MKAnnotation 错误,符合协议(protocol)

iOS SDK Mapview Annotation标注重绘错误

ios - 如何使用Webview将Facebook like按钮添加到iOS应用程序?

ios - Objective-C 从字符串中获取类属性

iphone - 在应用程序购买中实现并在iPhone中恢复

iphone - 为什么地址词典中没有邮政编码?

iphone - 如何在 iOS 6 中更新 MKMapview?

ios - MKAnnotation 未声明