2015-09-21 31 views
6

在我的应用程序中,我使用固定比率(16x9)的自定义tableViewCells。为了达到这个目的,我在单元格中放置了一个视图,并将其固定到其父视图中(尽管我在界面构建器中完成了它:V/H:|-[innerView]-|)。 另外,我把比例限制在它。UITableViewAutomaticDimension在iOS 9中无法正常工作

在我的tableViewController中,我使用UITableViewAutomaticDimension作为表格单元高度。

预计行高度为180,至极的确切大小的电池将有320像素宽屏显示器上(如我,你可以看到,这样做)。

我还在部署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. 

我在这里看到的唯一的东西是iOS中扣除的丢失的0.5个像素。

+0

我在这里看到的唯一的东西是iOS中扣除的丢失的0.5像素魔法般的?这个信息在哪里? – BangOperator

+0

@somexyz读取记录的约束条件:'V:[UITableViewCellContentView:0x14da0ff60(179.5)]' –

回答

1

问题是tableview自动添加的两个约束。 UIView-Encapsulated-Layout-高度和宽度可能是在初始加载期间为单元格计算的表视图的高度和宽度,这是基于当时单元格的约束。

"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>", 
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>" 

至于这些约束的重点是1000你可以做的是降低你的高度和宽度约束优先事项,并让需要的(负载)时所采用的封装尺寸。

+0

这确实有帮助。感谢关于时间的简短解释(加载)。你能告诉一些有关iOS 8和iOS 9之间的区别吗?我绝对需要/想知道为什么只有iOS 9有不同的做法...... –

+0

我真的不知道iOS 9中的自动布局引擎发生了什么变化,但这也发生在iOS 8中。 – Istvan

+0

是的。就iOS8而言,这也可能发生,只要您在讨论这个或多或少的通用自动布局警告即可。在我的情况下,这个警告只出现在iOS9中,而不是8,因此我打开了这个问题。 –

1

似乎您在两个不同视图中添加了两个比率约束。

一个应该有,

<NSLayoutConstraint:0x14d939e00 UIView:0x14da107f0.width == 
1.77778*UIView:0x14da107f0.height> 

对UIView的0x14d939e00添加地址0x14da107f0内存地址。

另一个是打破。

<NSLayoutConstraint:0x14c5eae90 UIView:0x14c5ead30.height == 
    0.5625*UIView:0x14c5ead30.width> 

这个是在UIView(0x14c5ead30)上添加的。寻找这个视图并删除这个比例约束。

+0

对不起,我把一个日志的开头和另一个日志的结尾混为一谈。这就是为什么地址和价值观都不合适的原因。只有一个限制,因为它在iOS 8中运行良好,我不认为这是一个普通的自动布局问题。 –