【问题标题】:How to set the rotation center of an MKAnnotationView如何设置 MKAnnotationView 的旋转中心
【发布时间】:2012-07-22 17:11:42
【问题描述】:

当在 MKMapView 上启用 MKUserTrackingModeFollowWithHeading 时,我的 MKAnnotationViews 出现问题。

我使用 MKAnnotationView 的 centerOffset 属性定位我的图像。指定针尖相对于图像中心坐标系的坐标有点违反直觉,但我想出了以下公式:

annotationView.centerOffset = CGPointMake(imageWidth/2.0 - tipXCoordinate, imageHeight/2.0 - tipYCordinate);

这适用于放大和缩小地图。图钉的尖端保持它们在地图上的相对位置。

但是,当我启用MKUserTrackingModeFollowWithHeading 时,它将不再起作用。 Pins 围绕图像的中心而不是尖端旋转。因此,当地图旋转时,提示不会指向它们应该标注的位置。

我对@9​​87654327@ 的framecenterproperties 进行了一些尝试,但我觉得它们对引脚的对齐没有任何影响。

有趣的是,MKPinAnnotationView 似乎根本没有使用centerOffset,而是使用了一个移位的frame。但是,我无法重现这一点。更改我的自定义视图的frame 根本没有移动它。

感谢您提供的任何见解:-)

解决方案:

不要使用中心偏移!请改用annotationView.layer.anchorPoint。锚点的坐标系也更好。图像矩形的坐标范围从 0.0(上/左)到 1.0(下/右):

annotationView.layer.anchorPoint = CGPointMake(tipXCoordinate/imageWidth, tipYCordinate/imageHeight);

【问题讨论】:

    标签: mkmapview mkannotationview mkpinannotationview


    【解决方案1】:

    一位朋友让我告诉你,你应该“试试这个”:

    self.layer.anchorPoint = CGPointMake (0.5f, 1.0f);
    

    【讨论】:

    • 告诉你的朋友,他是我本周的个人英雄 :-) 非常感谢!
    猜你喜欢
    • 2013-02-12
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2016-07-07
    • 2016-01-16
    • 1970-01-01
    • 2017-06-07
    • 2013-01-06
    相关资源
    最近更新 更多