UITableViewCell LayoutConstraint (UIView-Encapsulated-Layout-Height)

iOS的LayoutConstraint总会莫名出现很多很奇怪的警告,虽然它不影响工程的正常运行,但是每每看到终端输出一大堆的警告提示,对于我们这些有洁癖的人,怎么能够容忍。今天说说我在开发ZHChat时遇到的一个LayoutConstraint问题:UIView-Encapsulated-Layout-Height.

我的Cell布局

UITableViewCell LayoutConstraint (UIView-Encapsulated-Layout-Height)_第1张图片
屏幕快照 2016-09-02 11.07.19.png

没有红色错误和黄色警告提示,一切看起来很正常。
但是一运行,后台一堆LayoutConstraint警告。

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
)

Will attempt to recover by breaking constraint 


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.

看警告提示是我的Constraint设置有问题,第一反应去check我的xib中的约束,逐个约束检查后还是没有问题。然后继续看警告提示,UIView-Encapsulated-Layout-Height 说明是高度约束设置不当,而警告中我的Label的Height有变动,查看我Xib中原始的约束是:

UITableViewCell LayoutConstraint (UIView-Encapsulated-Layout-Height)_第2张图片
屏幕快照 2016-09-02 11.17.24.png

看到这里我想大家应该知道是什么原因导致的了,没错就是Equal导致的,修改Equal为Less Than or Equal后警告解决。

这里还有一个快速定位方法就是改变Cell的宽度和高度后如果出现警告,说明约束肯定设置不当!

你可能感兴趣的:(UITableViewCell LayoutConstraint (UIView-Encapsulated-Layout-Height))