转载

Crash related to `UIVisualEffectView`

尝试在storyboard中添加了一个 UIVisualEffectView ,然后又添加了几个子视图,然后,就咻的一下,挂了。

2016-03-02 14:57:45.953 K06-Where[3499:225450] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7f843501d7f0 UIView:0x7f843501da50.centerX == UIVisualEffectView:0x7f843501d150.centerX>     When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:] to debug. 2016-03-02 14:57:45.954 K06-Where[3499:225450] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x7f843501e250 UIView:0x7f843501da50.top == UIVisualEffectView:0x7f843501d150.top + 66> 

command + shift + 0 查一下苹果的文档:

After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself. (From :apple: )

如同 UITableViewCell 一样, UIVisualEffectView 有自己的 contentView 。所以,不管是添加子视图,还是添加子视图相关的约束,都应该加在这个 contentView 上,而不是直接加到 UIVisualEffectView 上。上面的crash就是由于子视图添加的约束不符合视图树的规则导致的。

知道了这些,把原本添加在 UIVisualEffectView 的约束删掉,改为添加到它的 contentView 上。Over~

原文  http://www.calios.gq/2016/03/02/Crash-related-to-UIVisualEffectView/
正文到此结束
Loading...