ios - 使用自动布局的 UITableViewCell 中的单个 UIImageView
<p><p>我正在尝试使用带有 AutoLayout 的动态单元格高度(即 <code>tableView.rowHeight = UITableViewAutomaticDimension</code>)将包含单个 UIImageView 的 UITableViewCell 放置在 UITableView 中。</p>
<p>我将要显示的图像具有特定的比例 (1000:667),但除了图像单元格之外还有其他单元格。我已经为此单元格构建了我的约束逻辑,以尊重 UIImageView 的 <strong>Aspect Ratio</strong>。 </p>
<p>因此,为避免畸形或部分图像未显示(剪辑 subview ),纵横比约束应根据设备屏幕宽度确定单元格的高度。</p>
<p>该单元是在具有以下约束的 Nib 文件中构建的:</p>
<p> <a href="/image/Nf0DT.png" rel="noreferrer noopener nofollow"><img src="/image/Nf0DT.png" alt="IB constraints"/></a> </p>
<p>显然<strong>这是可行的</strong>,因为单元格的高度会在运行时根据所使用的设备(模拟器)进行相应设置。</p>
<p>问题是我得到了很多打破约束的错误日志(如下)。任何想法为什么 iOS/table view 提示这个约束? </p>
<p>对于显示尊重纵横比的 UITableViewCell 的不同方法的建议也将不胜感激。</p>
<pre><code>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.
(
"<NSLayoutConstraint:0x7ff5097a7910 UIImageView:0x7ff5097393a0.width == 1.49925*UIImageView:0x7ff5097393a0.height>",
"<NSLayoutConstraint:0x7ff509739550 V:|-(0)- (Names: '|':UITableViewCellContentView:0x7ff5097a8e10 )>",
"<NSLayoutConstraint:0x7ff5097aa180 UIImageView:0x7ff5097393a0.centerY == UITableViewCellContentView:0x7ff5097a8e10.centerY>",
"<NSLayoutConstraint:0x7ff5097a8c70 H:|-(0)- (Names: '|':UITableViewCellContentView:0x7ff5097a8e10 )>",
"<NSLayoutConstraint:0x7ff5097a8cc0 H:-(0)-| (Names: '|':UITableViewCellContentView:0x7ff5097a8e10 )>",
"<NSLayoutConstraint:0x7ff5097b6440 'UIView-Encapsulated-Layout-Height' V:>",
"<NSLayoutConstraint:0x7ff5097b4930 'UIView-Encapsulated-Layout-Width' H:>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff5097a7910 UIImageView:0x7ff5097393a0.width == 1.49925*UIImageView:0x7ff5097393a0.height>
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.
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是因为你给了不必要的自动布局(高度、宽度和中心 y)冲突。</p>
<p>例如。你给了高度然后是顶部和底部,高度是固定的,你还是给了顶部和底部对齐...这是不必要的...</p>
<p> <a href="/image/r6VlQ.png" rel="noreferrer noopener nofollow"><img src="/image/r6VlQ.png" alt="enter image description here"/></a> </p>
<p>你可以试试这个建议。</p>
<p><code>1)center y + Trailing + Leading + Height.</code>
<code>2)顶部 + 底部 + 尾随 + 前导。</code>
<code>3)height + width + center y +leading</code>
还有更多</p>
<p>希望你明白……</p></p>
<p style="font-size: 20px;">关于ios - 使用自动布局的 UITableViewCell 中的单个 UIImageView,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39331280/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39331280/
</a>
</p>
页:
[1]