代码如下:
注意priority high是关键
class YYCell: UITableViewCell {
fileprivate var tvHeightConstraint: Constraint? = nil
....
fileprivate func setupUI() {
textView.snp.makeConstraints { (make) in
make.top.equalToSuperview().offset(20)
make.leading.trailing.bottom.equalToSuperview()
tvHeightConstraint = make.height.equalTo(0).priority(.high).constraint
}
}
...更新时候...
fileprivate func bind() {
_ = tvHeightConstraint?.update(offset: height)
}
}
class YYCell: UITableViewCell {
fileprivate var tvHeightConstraint: Constraint? = nil
....
fileprivate func setupUI() {
textView.snp.makeConstraints { (make) in
make.top.equalToSuperview().offset(20)
make.leading.trailing.bottom.equalToSuperview()
tvHeightConstraint = make.height.equalTo(0).priority(.high).constraint
}
}
...更新时候...
fileprivate func bind() {
_ = tvHeightConstraint?.update(offset: height)
}
}
class YYCell: UITableViewCell { fileprivate var tvHeightConstraint: Constraint? = nil .... fileprivate func setupUI() { textView.snp.makeConstraints { (make) in make.top.equalToSuperview().offset(20) make.leading.trailing.bottom.equalToSuperview() tvHeightConstraint = make.height.equalTo(0).priority(.high).constraint } } ...更新时候... fileprivate func bind() { _ = tvHeightConstraint?.update(offset: height) } }