SnapKit如果高度要稍后才能确定,如何设置才能保证不冲突

代码如下:

注意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)
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *