Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why don't allow updateConstraints to update multiplier? #386

Closed
3 tasks done
semiwhale opened this issue Jan 4, 2017 · 3 comments
Closed
3 tasks done

Why don't allow updateConstraints to update multiplier? #386

semiwhale opened this issue Jan 4, 2017 · 3 comments

Comments

@semiwhale
Copy link

semiwhale commented Jan 4, 2017

New Issue Checklist

  • I have looked at the Documentation
  • I have read the F.A.Q.
  • 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?

@robertjpayne
Copy link
Member

@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.

@AL-bruce
Copy link

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

@AL-bruce
Copy link

16231574942823_ pic_hd
this is the reslut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants