MKAnnotation image offset with custom pin image

前端 未结 4 1710
不思量自难忘°
不思量自难忘° 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

    Setting the centerOffset often moves the image arround when user rotates or zooms the map, as anchor point is still set to the center of the image instead of its lower center.

    You can set the anchor point of the annotation to the bottom center of you custom image as follows:

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

    This way when user zooms or rotates the map your custom annotation will never move from its coordinates on the map.

提交回复
热议问题