gpt4 book ai didi

iphone - 如何将 MKMapView 用户位置蓝点更改为选择的图像?

转载 作者:IT王子 更新时间:2023-10-29 07:45:55 27 4
gpt4 key购买 nike

是否可以更改 blue dot哪个指示用户在 MKMapView 中的位置到图像?例如一辆小汽车或任何 .png 图片?

enter image description here

最佳答案

MKMapViewDelegateviewForAnnotation: 方法中,您可能会有这样的代码。

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

if (annotation == mapView.userLocation) return nil;
...

如果 annotationuserLocation,我们返回 nilmapView 显示蓝点和圆圈动画.为了显示我们对 userLocation 的自定义注释,只需删除行 return nil; 并在那里进行自定义。

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

static NSString* AnnotationIdentifier = @"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];

if (!pinView) {

MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
if (annotation == mapView.userLocation){
customPinView.image = [UIImage imageNamed:@"myCarImage.png"];
}
else{
customPinView.image = [UIImage imageNamed:@"mySomeOtherImage.png"];
}
customPinView.animatesDrop = NO;
customPinView.canShowCallout = YES;
return customPinView;

} else {

pinView.annotation = annotation;
}

return pinView;
}

关于iphone - 如何将 MKMapView 用户位置蓝点更改为选择的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6293432/

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