Info | Value |
-------------------------|-------------------------------------|
Platform | iOS
Platform Version | 10.2
SnapKit Version | 3.1.2
Integration Method | carthage
view.snp.makeConstraints { (make) in
make.height.equalTo(view.snp.width).multipliedBy(1.2)
}
view.snp.updateConstraints { (make) in
make.height.equalTo(view.snp.width).multipliedBy(1.1)
}
fatal error: Updated constraint could not find existing matching constraint to update.
I looked at doc. I found:
Alternative if you are only updating the constant value of the constraint you can use the method snp.updateConstraints instead of snp.makeConstraints
internal func ==(lhs: LayoutConstraint, rhs: LayoutConstraint) -> Bool {
guard lhs.firstItem === rhs.firstItem &&
lhs.secondItem === rhs.secondItem &&
lhs.firstAttribute == rhs.firstAttribute &&
lhs.secondAttribute == rhs.secondAttribute &&
lhs.relation == rhs.relation &&
lhs.priority == rhs.priority &&
lhs.multiplier == rhs.multiplier else {
return false
}
return true
}
firstItem, secondItem, firstAttribute, secondAttribute, relation, priority is enough to identify a constraint. Why don't allow updating multiplier?
@semiwhale thanks for this, unfortunately NSLayoutConstraint's API's do not allow updating the multiplier (you have to re-build the constraint from scratch) hence we cannot do it via SnapKit.
SnapKit's update method is an optimised update, it only updates the .constant
value of the NSLayoutConstraint(s) for performance reasons.
label adaptive height on cell
i have set numberOfLines ,while have a cell show mistake.
this is my code
self is a view and self is a part of cell
that i mean the view adaptive height is wrong
self.addSubview(self.titleBtn)
self.addSubview(self.titleDesLabel)
self.titleBtn.snp.makeConstraints { (make) in
make.top.left.right.equalToSuperview()
}
self.titleDesLabel.snp.makeConstraints { (make) in
make.top.equalTo(self.titleBtn.snp.bottom).offset(4)
make.left.equalToSuperview()
make.right.equalToSuperview()
}
self.snp.makeConstraints { (make) in
make.bottom.equalTo(self.titleDesLabel.snp.bottom)
make.left.equalTo(self)
make.top.equalTo(self)
make.right.equalTo(self)
}
this is the reslut
Most helpful comment
@semiwhale thanks for this, unfortunately NSLayoutConstraint's API's do not allow updating the multiplier (you have to re-build the constraint from scratch) hence we cannot do it via SnapKit.
SnapKit's update method is an optimised update, it only updates the
.constant
value of the NSLayoutConstraint(s) for performance reasons.