gpt4 book ai didi

iphone - 在 MKMapview 中显示不同的 Pin 图片

转载 作者:可可西里 更新时间:2023-11-01 03:37:32 25 4
gpt4 key购买 nike

在我的 MKMap View 中,我用图像自定义了注释图钉。但仍有一些图钉是静态的,没有显示给定的图像。

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

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

-(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;
}

enter image description here

有什么想法吗?

最佳答案

如果您想要在 MKAnnotationView 上使用与苹果“Pin”不同的图像,则必须使用 MKAnnotationView 而不是 MKPinAnnotationView

MKPinAnnotationView 不打算以这种方式进行自定义,并且会不时地显示 Pin。Class Reference表明只有 pinColoranimatesDrop 应该被改变。

不过,您将失去 PinAnnotationView 的动画和阴影。

关于iphone - 在 MKMapview 中显示不同的 Pin 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14999128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com