MKMapView 忽略 iOS 4 中 centerOffset 的更新
我之前创建了一个自定义标注气泡作为 MKAnnotationView 的子视图,因为内置标注非常有限。这要求我在选择 MKAnnotationView 时更改为 centerOffset 以考虑标注气泡的大小。在 iOS 4 发布之前,这一切都运行得非常完美。现在,在 iOS 4 中,它完全忽略了我对 centerOffset 属性的更新,因此图钉和气泡似乎向下向右跳跃(标注气泡的左上角现在位于图钉点应该所在的位置) 。
有谁知道为什么 iOS 4 中发生了这种变化?我可以做些什么来让 MKMapView 识别新的 centerOffset 吗?这是苹果引入的错误吗?
感谢您的帮助!
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 the MKAnnotationView when it is selected to account for the size of the callout bubble. This all worked perfectly before iOS 4 came out. Now, with iOS 4, it completely ignores my updating of the centerOffset property and therefore the pin and bubble appear to jump down and to the right (the top left corner of the callout bubble is now at the location where the pin point should be).
Does anyone know why this has changed in iOS 4? Is there something I can do to get the MKMapView to recognize the new centerOffset? Is this a bug that apple introduced?
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您使用的是 MKAnnotationView 而不是 MKPinAnnotationView!您无法设置 MKPinAnnotationView 对象的 centerOffset (当然,除非您是子类)。
Make sure you are using MKAnnotationView and not MKPinAnnotationView! You can't set the centerOffset of a MKPinAnnotationView-object (except if you subclass of course).
我有同样的问题 - centerOffset 似乎只在第一次被考虑。
它在内部发生了变化,但视图没有移动——所以你需要做的是自己移动视图。
您可以通过根据所需的偏移调整视图的中心来移动视图 - 所选视图与未选择的视图在左上角保持对齐,因此您需要重新对齐它们的中心。这是我的情况:
选择->未选中:
未选中->选定:
其中 130 是视图之间的高度差(中心点在底部),56 是它们中心的 X 偏移量之间的差。
请记住 - 您仍然需要更改中心偏移,因为缩放时会考虑到它。
希望这会有所帮助,我为此浪费了几个小时。请记住向 Apple 提交错误报告。
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:
Unselected -> Selected:
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.
我认为您可以使用在所有版本中都可以正常工作的
setRegion
而不是centerOffset
。I think instead of
centerOffset
you can usesetRegion
which works fine in all versions.