如何设置MKAnnotationView的旋转中心 [英] How to set the rotation center of an MKAnnotationView

查看:117
本文介绍了如何设置MKAnnotationView的旋转中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MKMapView上启用MKUserTrackingModeFollowWithHeading时,我的MKAnnotationView出现了问题.

I've got a problem with my MKAnnotationViews when MKUserTrackingModeFollowWithHeading is enabled on the MKMapView.

我使用MKAnnotationView的centerOffset属性定位了图像.指定销钉尖端相对于图像中心坐标系的坐标有点反推,但我想出了以下公式:

I positioned my images using the centerOffset property of the MKAnnotationView. Specifying the coordinates of the pin's tip relative to the coordinate system at the center of the image is somewhat counter-intutive, but I came up with the following formula:

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

此功能适用于放大和缩小地图.销钉的尖端在地图上保持相对位置.

This works fine for zooming the map in and out. The tips of the pins keep their relative position on the map.

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

However, when I enable MKUserTrackingModeFollowWithHeading, it won't work anymore. The Pins rotate around the center of the image, instead of the tip. So when the map rotates, the tips do no point to the locations they are supposed to annotate.

我对MKAnnotationViewframecenter属性进行了一些尝试,但是我觉得它们对销的对齐方式没有任何影响.

I've played around a bit with the frameand centerproperties of the MKAnnotationView, but I feel, they are having no effect on the alignement of the pins whatsoever.

有趣的是,MKPinAnnotationView似乎根本没有使用centerOffset,而是使用了移位的frame.但是,我无法重现此内容.更改自定义视图的frame根本不会移动它.

Interestingly, the MKPinAnnotationView does not seem to use centerOffset at all, but a shifted frame instead. However, I was unable to reproduce this. Changing the frame of my custom view did not move it at all.

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

Thanks for any insights you can provide :-)

解决方案:

请勿使用centerOffset!使用annotationView.layer.anchorPoint代替.起点的坐标系也好得多.坐标范围是图像矩形的0.0(上/左)到1.0(下/右):

Don't use centerOffset! Use annotationView.layer.anchorPoint instead. The coordinate system of achor point is much nicer, too. Coordinates range from 0.0 (top/left) to 1.0 (bottom/right) of the image rectangle:

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

推荐答案

一个朋友问我,让你知道你应该尝试一下":

A friend asks me to let you know that you should "try this for instance":

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

这篇关于如何设置MKAnnotationView的旋转中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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