gpt4 book ai didi

iPhone核心位置: DIfferentiate pin for custom pin image

转载 作者:行者123 更新时间:2023-12-03 19:46:23 29 4
gpt4 key购买 nike

我正在使用

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

为自定义图钉绘制我自己的图像。我想为不同的引脚使用不同的图像。我想知道如何区分哪个引脚正在调用此函数。

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

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
annView.canShowCallout = YES;

annView.calloutOffset = CGPointMake(-5, 5);

if ([annView.annotation.title isEqualToString:myLocation]) {
UIImage *pinImage = [UIImage imageNamed:@"myLocationImage.png"];
[annView setImage:pinImage];
} else {
UIImage *pinImage = [UIImage imageNamed:@"resImage.png"];
[annView setImage:pinImage];
}

return annView;
}

编辑:在新项目中重新审视这一点,我意识到创建不同的引脚类是浪费的。更好的实现是设置引脚类型,然后从 MKAnnotationView 的注释中读取它。下面的例子。

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

MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinID"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[button addTarget:self action:@selector(viewStoreDetails:) forControlEvents:UIControlEventTouchDown];

pin.rightCalloutAccessoryView = button;
pin.canShowCallout = YES;
pin.calloutOffset = CGPointMake(-5, 5);

Annotation *a = (Annotation *)pin.annotation;

int i = a.locationType;

switch (i) {
case RETAIL:
pin.image = [UIImage imageNamed:@"pin_retail.png"];
break;
case OUTLET:
pin.image = [UIImage imageNamed:@"pin_outlet.png"];
break;
case COMING_SOON:
pin.image = [UIImage imageNamed:@"pin_coming_soon.png"];
break;
case MY_LOCATION:
pin.image = [UIImage imageNamed:@"pin_my_location.png"];
break;
pin.image = [UIImage imageNamed:@"pin_retail.png"];
default:
break;
}

return [pin autorelease];
}

最佳答案

annView.annotation.title 成功了。

关于iPhone核心位置: DIfferentiate pin for custom pin image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3576882/

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