首页 > 代码库 > 使用autolayout常见错误

使用autolayout常见错误

使用autolayout常见错误

1:The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x8e82e40 UISearchBar:0x8e7fa80.top == UIView:0x8b7c510.top + 20>
    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 _viewHierarchyUnpreparedForConstraint:] to debug.

这个错误是创建完searchBar以后要马上添加到当前view中,否则添加约束的时候就会有警告。把红线圈住的代码移动到箭头所指的地方就行。

技术分享

使用autolayout常见错误