MKMapView ignores update of centerOffset in iOS 4

前端 未结 3 823
别那么骄傲
别那么骄傲 2021-01-04 08:43

I previously created a custom callout bubble as a subview to the MKAnnotationView because the built in callout is so limited. This requires me to change to centerOffset of

3条回答
  •  忘掉有多难
    2021-01-04 09:46

    I have the same problem - centerOffset seems to be taken into account only the first time. It is changed internally, but the view is not moved - so what you need to do is move the view yourself.

    You can move the view by adjusting its center with the required offset - the selected view remains aligned at the top-left corner with the unselected view, so you need to realign their centers. Here's my case:

    Selected -> Unselected:

    self.center = CGPointMake(self.center.x + 56.0, self.center.y + 130.0);
    self.centerOffset = CGPointMake(5.0, -14.0);
    

    Unselected -> Selected:

    self.center = CGPointMake(self.center.x - 56.0, self.center.y - 130.0);
    self.centerOffset = CGPointMake(64.0, -81.0);
    

    Where 130 is the difference in height between the views(center point is at the bottom), and 56 is the difference between the X offsets of their centers.

    Remember - you still need to change the center offset because it'll be taken into account when zooming.

    Hope this helps, I've lost a few hours on this. Remember to submit a bug report to Apple.

提交回复
热议问题