我試圖將包含單個UIImageView的UITableViewCell放置在使用動態單元高度和AutoLayout(即tableView.rowHeight = UITableViewAutomaticDimension
)的UITableView中。使用Autolayout在UITableViewCell中的單個UIImageView
我將顯示的圖像具有特定的比例(1000:667),但除圖像單元格外還有其他單元格。我已經爲這個單元格建立了我的約束邏輯,以尊重UIImageView的長寬比。
因此,爲避免畸形或部分圖像未顯示(剪輯子視圖),寬高比約束應根據設備屏幕寬度確定單元的高度。
細胞建於有以下限制nib文件:
顯然這個作品,由於細胞的高度相應地設置上取決於所使用的設備(仿真器)上運行時。
問題是我得到了很多突破性約束錯誤日誌(如下)。任何想法爲什麼iOS /表查看抱怨這個約束?
關於顯示尊重寬高比的UITableViewCell的不同方法的建議也將被讚賞。
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)-[UIImageView:0x7ff5097393a0] (Names: '|':UITableViewCellContentView:0x7ff5097a8e10)>",
"<NSLayoutConstraint:0x7ff5097aa180 UIImageView:0x7ff5097393a0.centerY == UITableViewCellContentView:0x7ff5097a8e10.centerY>",
"<NSLayoutConstraint:0x7ff5097a8c70 H:|-(0)-[UIImageView:0x7ff5097393a0] (Names: '|':UITableViewCellContentView:0x7ff5097a8e10)>",
"<NSLayoutConstraint:0x7ff5097a8cc0 H:[UIImageView:0x7ff5097393a0]-(0)-| (Names: '|':UITableViewCellContentView:0x7ff5097a8e10)>",
"<NSLayoutConstraint:0x7ff5097b6440 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff5097a8e10(276)]>",
"<NSLayoutConstraint:0x7ff5097b4930 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7ff5097a8e10(414)]>"
)
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.
我也嘗試了不同的約束方法,如更換'居中y以:Superview'的'平等寬度改爲:SuperView',結果相同。 – Fdo
如果你想UIImageView高度被固定,那麼你只有頂部或底部約束。另外如果你有中心對齊和高度,那麼不需要頂部和底部約束。如果你想UIImageView寬度被修復,那麼你需要前導或尾隨約束。 – sschunara
只需移除imageView的固定高度和寬度以及中心對齊。將解決這個問題。 –