MKAnnotation image offset with custom pin image

前端 未结 4 1688
不思量自难忘°
不思量自难忘° 2020-12-04 19:04

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 c

4条回答
  •  独厮守ぢ
    2020-12-04 19:51

    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);
    

提交回复
热议问题