用户点击时更改图钉颜色 [英] Change Pin Color when user tapped

查看:106
本文介绍了用户点击时更改图钉颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户固定修改标题和副标题时,我会将注释的颜色从红色更改为绿色.

I would change the color from red to green of an annotation when the user pin tapped addition to changing its title and subtitle.

我真的迷路了.我搜索了如何制作自定义注释图钉,确定.当用户触摸didSelectAnnotationView引脚时,我发现了该方法的实现,当我点击注释NSLog(@"Tap") ;时,该方法可以工作,但是现在我无法更改被触摸的引脚.

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") ; , but now I can not change the pin that was touched.

非常感谢大家的贡献.

Ciao

推荐答案

要设置图钉颜色,请使用

To set the pin color, make use of MKPinAnnotationView pinColor property.

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

对于自定义注释图像,请设置image属性.

For custom annotation image, set the image property, as such.

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

请注意如何为MKAnnotationView放置动画?

Do note that the MKPinAnnotationView animateDrop property will not work on custom images. There's a way to duplicate that animation though. See How do I animate MKAnnotationView drop?

更新 因此,基本上来说,如果您希望在被选中时从红色变为绿色,则可以执行此操作.

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

这篇关于用户点击时更改图钉颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆