gpt4 book ai didi

iphone - 使用自动布局子类化 MKAnnotationView

转载 作者:行者123 更新时间:2023-12-01 17:23:25 26 4
gpt4 key购买 nike

我喜欢 iOS 6 中新的自动布局功能,但是在将它与我的 MKAnnotationView 子类结合使用时遇到了一些麻烦。

我在初始化方法中禁用了自动调整掩码转换。

self.translatesAutoresizingMaskIntoConstraints = NO;

但是,当我加载使用我的子类注释的 MKMapView 时,该应用程序会引发 NSInternalInconsistencyException。
*** Assertion failure in -[ENMapAnnotationView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. ENMapAnnotationView's implementation of -layoutSubviews needs to call super.'

我没有覆盖 -layoutSubviews 所以对我来说这看起来苹果的 MKAnnotationView 实现还没有准备好自动布局。 是否有一些聪明的方法可以解决 MKAnnotationView 中缺少自动布局支持的问题,以便我可以在我的子类中使用自动布局?

最佳答案

注释 View 的自动布局在 iOS SDK 8 之前运行良好。在 iOS SDK 8 中,我看到具有动态约束的 View 的行为非常奇怪,它们在整个 map 上移动,有时甚至对齐左上角。

解决方案是 setTranslatesAutoresizingMaskIntoConstraints:YES

[annotationView setBounds:CGRectMake(0, 0, width, height)];

并使用从 subview 计算的宽度和高度。然后至少您可以对 subview 使用约束。

关于iphone - 使用自动布局子类化 MKAnnotationView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14591366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com