让pin在你的Map上自由驰骋

无论是自定义的MKAnnotationView还是标准的,一旦addAnnotation to MapView,如何更新它在地图上的位置呢?更新MKAnnotation protocol中的coordinate可以做到吗? 如果是手动更新位置是不可以让它在地图上移动的。请看官网文档 ,其中有一段描述

 

Important: When you implement the coordinate property in your class, it is recommended that you synthesize its creation. If you choose to implement the methods for this property yourself, or if you manually modify the variable underlying that property in other parts of your class after the annotation has been added to the map, be sure to send out key-value observing (KVO) notifications when you do. Map Kit uses KVO notifications to detect changes to the coordinatetitle, and subtitle properties of your annotations and make any needed changes to the map display. If you do not send out KVO notifications, the position of your annotations may not be updated properly on the map.

 

For more information about how to implement KVO-compliant accessor methods, see Key-Value Observing Programming Guide.”

 

手动更新后必须用KVO的方式通知系统,不然系统是不知道更新位置的。如何通知道呢,其实NSObject中有这样的方法willChangeValueForKey and didChangeValueForKey。如你写了个方法更新pin位置,如下:

 

 

IOS4中更新更简单,只需要调用- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;这个方法就可以自动更新了。

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo} span.s1 {color: #be299d} span.s2 {color: #733ea4}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值