子类MKAnnotationView与使用的自动布局 [英] Subclassing MKAnnotationView with use of auto layout

查看:190
本文介绍了子类MKAnnotationView与使用的自动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在iOS 6中新的自动排版功能,但我结合我MKAnnotationView子类,使用时遇到了一点麻烦。

I like the new auto layout functionality in iOS 6 but I've run into a bit of trouble when using it in combination with my MKAnnotationView subclass.

我已经禁用了自动尺寸调整掩码翻译初始化方法。

I've disabled the autoresizing mask translation in the initialization method.

self.translatesAutoresizingMaskIntoConstraints = NO;

但是,当我加载使用我的子类的一个注解的MKMapView应用程序抛出NSInternalInconsistencyException。

But the app throws an NSInternalInconsistencyException when I load the MKMapView that uses an annotation of my subclass.

*** 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,所以我可以在我的子类中使用自动布局?自动布局支持

推荐答案

对于自动版式注解视图工作得很好,直到iOS版SDK 8. iOS版SDK 8我看到与动态约束的看法很奇怪的行为,他们在地图上移动的所有有时甚至对齐左上角。

AutoLayout for annotation views worked fine until iOS SDK 8. With iOS SDK 8 I see really strange behaviour of views with dynamic constraints, they are moving all over the map or sometimes even align top left.

溶液 setTranslatesAutoresizingMaskIntoConstraints:YES

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

和使用的宽度和高度从子视图计算。那么至少你可以使用约束子视图。

and use width and height calculated from the subviews. Then at least you can use constraints for the subviews.

这篇关于子类MKAnnotationView与使用的自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆