简体   繁体   English

用户点击时更改引脚颜色

[英]Change Pin Color when user tapped

I would change the color from red to green of an annotation when the user pin tapped addition to changing its title and subtitle. 当用户引脚添加更改其标题和副标题时,我会将注释的颜色从红色更改为绿色。

I am truly lost. 我真的迷路了。 I searched how to make a custom annotation pin, ok. 我搜索了如何制作自定义注释引脚,好的。 I found the implementation of the method when the user touches the pin didSelectAnnotationView and it works when I tap the annotation NSLog(@"Tap") ; 当用户触摸引脚didSelectAnnotationView时,我找到了该方法的实现,当我点击注释NSLog(@"Tap") ;时,它可以工作NSLog(@"Tap") ; , but now I can not change the pin that was touched. ,但现在我无法改变被触摸的引脚。

Thank you very much everyone for your contributions. 非常感谢大家的贡献。

Ciao 再见

To set the pin color, make use of MKPinAnnotationView pinColor property. 要设置引脚颜色,请使用MKPinAnnotationView pinColor属性。

MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] init]
pin.pinColor = MKPinAnnotationColorGreen;

For custom annotation image, set the image property, as such. 对于自定义注释图像,请设置图像属性。

UIImage *annImage = [UIImage imageNamed:@"AnnotationIcon.png"];
annView.image = annImage;

Do note that the MKPinAnnotationView animateDrop property will not work on custom images. 请注意, MKPinAnnotationView animateDrop属性不适用于自定义图像。 There's a way to duplicate that animation though. 有一种方法可以复制那个动画。 See How do I animate MKAnnotationView drop? 请参阅如何为MKAnnotationView动画下拉?

Update So bascially, you do this if you wanna change from red to green upon being selected. 更新所以,基本上,如果您想在被选中时从红色变为绿色,则执行此操作。

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view {
    view.pinColor = MKPinAnnotationColorGreen;

}

- (MKAnnotationView *)mapView:(MKMapView *)aMapView
            viewForAnnotation:(id)ann {

    NSString *identifier = @"myPin";
    MKPinAnnotationView *annView = (MKPinAnnotationView *)
    [aMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (annView == nil) {
        annView= [[[MKPinAnnotationView alloc] initWithAnnotation:ann
                                               reuseIdentifier:identifier]
               autorelease];
    } else {
        annView.annotation = ann;
    }
// you can define the properties here.

return annView;
}

在你的方法设置pinColor你的财产MKAnnotationView如下:

annotationView.pinColor = MKPinAnnotationColorRed; // Green or Purple

(re) look this : (重新)看这个:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view {
    view.pinColor = MKPinAnnotationColorGreen;

}

this is a MKPinAnnotationView (and not MKAnnotationView ) in param 这是param中的MKPinAnnotationView (而不是MKAnnotationView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM