导入SnapKit
import SnapKit
修改约束
var snpCenterX: Constraint?
var snpCenterY: Constraint?
/// 偏移量,默认 0
var offset:CGPoint = .zero {
didSet {
snpCenterX?.update(offset: offset.x)
snpCenterY?.update(offset: offset.y)
}
}
建立约束
viewTips.snp.makeConstraints { (make) in
/// 这个一会要加上偏移量
self.snpCenterX = make.centerX.equalTo(self).offset(offset.x).constraint
self.snpCenterY = make.centerY.equalTo(self).offset(offset.y).constraint
}