问题描述
我有一个带有自定义图钉图像的 MKAnnotation.但是 pin(MKAnnotationView) 将图像相对于指定的坐标居中.我想将坐标点设置在图像的底部中心,而不是中心.
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.
我尝试过使用 annView.centerOffset = CGPointMake(-12, -28);
.但问题是 centerOffset
与地图缩放级别无关.
I've tried using annView.centerOffset = CGPointMake(-12, -28);
. But the problem is that centerOffset
isn't relevant to the maps zoom level.
在 JS API 和 Android 中都可以做到这一点.有没有可能在objective-c中做到这一点?
One can do this both in the JS API and in Android. Is there any possibility to do this in objective-c?
..弗雷德里克
推荐答案
你的 UIAnnotationView
总是以相同的比例绘制,地图的缩放级别无关紧要.这就是 centerOffset
不受缩放级别约束的原因.
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
正是您所需要的.如果你发现你的 pin 不在合适的位置(例如,当你改变缩放级别时底部中心移动了一点),那是因为你没有设置正确的 centerOffset.
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.
顺便说一句,如果你想把坐标点设置在图片的底部中心,你的centerOffset的x坐标应该是0.0f,作为annotationView默认是图片居中.所以试试:
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 图像偏移与自定义图钉图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!