如何在不添加/删除地图的情况下移动MKAnnotation? [英] How to move a MKAnnotation without adding/removing it from the map?

查看:97
本文介绍了如何在不添加/删除地图的情况下移动MKAnnotation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以移动MKAnnotation的坐标而无需在地图中添加和删除注释?

Is it possible to move the coordinate of a MKAnnotation without adding and removing the annotation from the map?

推荐答案

我找到了一个非常简单的方法。我想平滑地更新我的玩家的位置而不删除然后重新添加玩家注释。这适用于iOS4之前的应用,它的作用是移动引脚并将地图置于引脚新位置的中心位置:

I found a pretty simple method. I wanted to update my player's position smoothly without removing and then re-adding the player annotation. This works well for pre-iOS4 apps, and what it does is both move the pin and center the map on the pin's new location:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[player setCoordinate:aLoc.coordinate];
[mapView setCenterCoordinate:aLoc.coordinate animated:NO];
[UIView commitAnimations];

这是相同的事情,但使用推荐的iOS4块功能:

Here's the same thing but using the recommended block feature for iOS4:

[UIView animateWithDuration:0.5 animations:^{
    [player setCoordinate:aLoc.coordinate];
    [mapView setCenterCoordinate:aLoc.coordinate animated:NO];
}];

这篇关于如何在不添加/删除地图的情况下移动MKAnnotation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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