Jul*_*ert 6 uitableview ios ios9
在我的应用程序中,我有自定义tableViewCells与固定比率(16x9).为了实现这一点,我在单元格中放置了一个视图,将其固定到其父视图(尽管我在界面构建器中进行了操作:) V/H:|-[innerView]-|.另外,我对它进行了比率约束.
在我的tableViewController中,我UITableViewAutomaticDimension用作表格单元格高度.
估计的行高是180,这是单元在320px宽显示器上的确切尺寸(正如你所看到的那样).
我仍在部署8.4,但是在使用iOS 9的设备上运行项目时,我收到了大量的自动布局警告,尽管一切正常并且看起来很完美.
警告本身是绝对正确的.有两个我不想要的限制 - 这些是iOS自己添加的.
2015-09-29 11:24:57.771 app[1039:324736] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>",
"<NSLayoutConstraint:0x147dd0210 H:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147deeca0 V:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149053c30 V:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147dbc2b0 H:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Run Code Online (Sandbox Code Playgroud)
我在这里看到的唯一一件事就是缺少了0.5个像素,iOS以某种方式神奇地减去了.
问题是表视图自动添加的两个约束。UIView-Encapsulated-Layout-Height 和 width 可能是初始加载期间根据当时单元格的约束为单元格计算的表格视图的高度和宽度。
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
Run Code Online (Sandbox Code Playgroud)
由于这些约束的优先级为 1000,因此您可以降低高度和宽度约束优先级,并在需要时(加载时)应用封装尺寸。