MKAnnotation图像偏移与自定义图钉图像 [英] MKAnnotation image offset with custom pin image
问题描述
我有一个带定制图钉的MKAnnotation。但是,引脚(MKAnnotationView)将图像与指定坐标相关联。我想设置在图像底部中心的坐标点,而不是中心。
我试过使用 annView.centerOffset = CGPointMake(-12,-28);
。但问题是 centerOffset
与地图缩放级别无关。
在JS API和Android中都可以做到这一点。有没有可能在Objective-C中做到这一点?
.. fredrik
您的 UIAnnotationView
总是以相同的比例绘制,地图的缩放级别无关紧要。这就是为什么 centerOffset
没有与缩放级别绑定的原因。
annView.centerOffset
就是你需要的。如果您发现您的别针不在合适的位置(例如,当您更改缩放级别时底部中心略微移动),这是因为您没有设置正确的centeroffset。
顺便说一下,如果要设置图像底部中心的坐标点,则centerOffset的x坐标应为0.0f,因为默认情况下,annotationView将图像居中。所以试试:
annView.centerOffset = CGPointMake(0,-imageHeight / 2);
I have a MKAnnotation with an custom pin image. However the pin(MKAnnotationView) centers the image in relation to the specified coordinate. I want to set the point of the coordinate at the bottom center of the image, not center.
I've tried using annView.centerOffset = CGPointMake(-12, -28);
. But the problem is that centerOffset
isn't relevant to the maps zoom level.
One can do this both in the JS API and in Android. Is there any possibility to do this in objective-c?
..fredrik
Your UIAnnotationView
is always drawn at the same scale, the map's zoom level doesn't matter. That's why centerOffset
isn't bound with the zoom level.
annView.centerOffset
is what you need. If you see that your pin is not at the good location (for example, the bottom center move a little when you change the zoom level), it's because you didn't set the right centerOffset.
By the way, if you want to set the point of the coordinate at the bottom center of the image, the x coordinate of your centerOffset should be 0.0f, as annotationView center the image by default. So try :
annView.centerOffset = CGPointMake(0, -imageHeight / 2);
这篇关于MKAnnotation图像偏移与自定义图钉图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!