当MKMapView启用MKUserTrackingModeFollowWithHeading
时,我遇到了MKAnnotationView
的问题。如何设置MKAnnotationView的旋转中心
我使用MKAnnotationView的centerOffset属性定位了我的图像。指定针的针尖相对于在图像的中心坐标系的坐标是有点反intutive,但我想出了下面的公式:
annotationView.centerOffset = CGPointMake(imageWidth/2.0 - tipXCoordinate, imageHeight/2.0 - tipYCordinate);
这工作正常,在放大和缩小地图。引脚的尖端保持其在地图上的相对位置。
但是,当我启用MKUserTrackingModeFollowWithHeading
时,它将不再工作。引脚围绕图像的中心旋转,而不是尖端。所以当地图旋转时,提示并不指向他们应该注释的位置。
我已经玩了frame
和center
属性MKAnnotationView
,但我觉得,他们没有任何影响的针脚alignement。
有趣的是,MKPinAnnotationView
似乎根本没有使用centerOffset
,而是改用frame
代替。但是,我无法重现这一点。更改我的自定义视图的frame
根本没有移动它。
感谢任何见解,可以提供:-)
解决方案:
不要使用centerOffset!改为使用annotationView.layer.anchorPoint
。 achor点的坐标系也更好。坐标范围为0.0(上/左)到1.0(下/右)的图像矩形为:
annotationView.layer.anchorPoint = CGPointMake(tipXCoordinate/imageWidth, tipYCordinate/imageHeight);
告诉你的朋友,(s)他是我本周的个人英雄:-)非常感谢! – Chris 2012-07-25 08:00:25