Snapkit: Why don't allow updateConstraints to update multiplier?

Created on 4 Jan 2017  路  3Comments  路  Source: SnapKit/SnapKit

New Issue Checklist

  • [x] I have looked at the Documentation
  • [x] I have read the F.A.Q.
  • [x] I have filled out this issue template.

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform | iOS
Platform Version | 10.2
SnapKit Version | 3.1.2
Integration Method | carthage

Issue Description

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?

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.

All 3 comments

@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)
}

16231574942823_ pic_hd
this is the reslut

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lolgear picture lolgear  路  5Comments

netgfx picture netgfx  路  3Comments

NicholasTD07 picture NicholasTD07  路  8Comments

aeves313 picture aeves313  路  4Comments

Cookiezby picture Cookiezby  路  8Comments