我有一个带动态高度单元格的UITableView。当我将静态高度约束(带有前导,顶部,尾部和底部约束)添加到UIView(在单元格中)时,一切都可以正常运行:
cell.layoutIfNeeded()
cell.setNeedsLayout()
var size = cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
问题是当我想为单元格内容添加宽高比时 - 我希望它与宽度具有相同的高度。但它始终以
失败(
"<NSLayoutConstraint:0x174291e40 UIView:0x174199f30.width == UIView:0x174199f30.height>",
"<NSLayoutConstraint:0x174291e90 H:[UIView:0x174199f30]-(10)-| (Names: '|':UITableViewCellContentView:0x174199e60 )>",
"<NSLayoutConstraint:0x174291ee0 V:[UIView:0x174199f30]-(19)-| (Names: '|':UITableViewCellContentView:0x174199e60 )>",
"<NSLayoutConstraint:0x174291f30 H:|-(10)-[UIView:0x174199f30] (Names: '|':UITableViewCellContentView:0x174199e60 )>",
"<NSLayoutConstraint:0x174291f80 V:|-(15)-[UIView:0x174199f30] (Names: '|':UITableViewCellContentView:0x174199e60 )>",
"<NSLayoutConstraint:0x17029af40 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x174199e60(600)]>",
"<NSLayoutConstraint:0x17029af90 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x174199e60(34)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174291e40 UIView:0x174199f30.width == UIView:0x174199f30.height>
我怎样才能做到这一点?