在MKMapview中显示不同的Pin图像

6 iphone map mkmapview mkannotation ios

在我的MKMap视图中,我使用图像自定义了注释引脚.但是仍然有些引脚是静态的并且没有显示给定的图像.

我正在使用 - (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id)注释来设置图钉图像.

在这里添加我的代码和屏幕:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
 {


if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]
                                 initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
    pinView.pinColor= MKPinAnnotationColorGreen;

    pinView.enabled = YES;
    pinView.canShowCallout = YES;
    pinView.image=[UIImage imageNamed:@"bublerest.png"]; //here I am giving the image  





UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];

    pinView.rightCalloutAccessoryView = rightButton;

UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rest_image2.png"]];
pinView.leftCalloutAccessoryView = profileIconView;


return pinView;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

有任何想法吗?

blu*_*lub 12

如果你想在MKAnnotationView苹果"Pin"上使用不同的图像,则必须使用a MKAnnotationView而不是a MKPinAnnotationView.

MKPinAnnotationView不是以这种方式定制的,并且会不时地显示Pin.本类参考表明,只有pinColoranimatesDrop应该被改变.

但是,您将丢失PinAnnotationView的动画和阴影.