我使用 UItableView
作为用户个人资料页面的基础。我有几个自定义单元格。第一个自定义单元格是包裹在 ScrollView 中的图像。当我打开此 View 时出现此错误:
"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86b6feb7e5b2b4e7b4bfb2b6c6c5e7f4e2c0f3eaeaf5e5f4e3e3e8d0efe3f1c5e9e8f2f4e9eaeae3f4a8f5f1efe0f2" rel="noreferrer noopener nofollow">[email protected]</a>#143 UIScrollView:SCROLL_VIEW.top == Lez.ProfileImagesCell:0x12a02e800.top>",
"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25155d14461517441c141d1565664457416350494956465740404b734c4052664a4b51574a494940570b56524c4351" rel="noreferrer noopener nofollow">[email protected]</a>#144 UIScrollView:SCROLL_VIEW.height == 512.0>",
"<SnapKit.LayoutConstraint:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="605018510350520159510550202301120426150c0c13031205050e36090517230f0e14120f0c0c05124e1317090614" rel="noreferrer noopener nofollow">[email protected]</a>#145 UIScrollView:SCROLL_VIEW.bottom == Lez.ProfileImagesCell:0x12a02e800.bottom - 16.0>",
"<NSLayoutConstraint:0x1c0094690 'UIView-Encapsulated-Layout-Height' Lez.ProfileImagesCell:0x12a02e800'ProfileImagesCell'.height == 44 (active)>"
这是此单元格的自定义代码:
class ProfileImagesCell: UITableViewCell {
var scrollView = UIScrollView()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupScrollView()
layoutIfNeeded()
}
private func setupScrollView() {
addSubview(scrollView)
let x = frame.width * 1.6
scrollView.snp.makeConstraints { (make) in
make.top.left.right.equalToSuperview()
make.height.equalTo(x)
make.bottom.equalToSuperview().inset(16)
}
scrollView.snp.setLabel("SCROLL_VIEW")
scrollView.auk.settings.contentMode = .scaleAspectFill
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
我认为高度有问题,但我无法解决这个问题。任何输入都会被赞赏。
最佳答案
这个冲突背后的原因UIView-Encapsulated-Layout-Height
是cell的初始高度,你可以尝试将scrollView底部约束的优先级设置为999,我的意思是这个
make.bottom.equalToSuperview().inset(16)
关于swift - Snapkit 和 TableView 中的多个自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49466878/