Snapkit: Change priorities

Created on 30 Jan 2015  ·  3Comments  ·  Source: SnapKit/SnapKit

I couldn't figure out how to change the priority of an already installed constraint.

Changing the priority of an NSLayoutConstraint is a cheap operation, and using a combination of priorities and .LessThanOrEqual + .GreaterThanOrEqual for animations is what Apple suggests.

It may even be nice to add some wrapper for this. You'd install

x ≦ 40
x ≧ 40 with priority P
x ≧ 20 with priority P + 1

and you'd then be able to switch x between 40 and 20 by changing the priority on the last constraint between P - 1 and P + 1.

enhancement

Most helpful comment

@danieleggert the develop branch now has support for updating priorities:

var constraint: Constraint? = nil
view.snp_makeConstraints { (make) -> Void in
    constraint = make.edges.equalTo(UIEdgeInsetsMake(10,10,10,10)).priorityHigh()
}
constraint?.updatePriorityLow()

All 3 comments

It's probably best we allow altering priorities via snp_updateConstraints. I'll see what this would entail and if it would have any implications.

@danieleggert the develop branch now has support for updating priorities:

var constraint: Constraint? = nil
view.snp_makeConstraints { (make) -> Void in
    constraint = make.edges.equalTo(UIEdgeInsetsMake(10,10,10,10)).priorityHigh()
}
constraint?.updatePriorityLow()

Hi @robertjpayne !
I'm trying to update priority as stated on the last comment.
But i Got this error:

Screen Shot 2020-07-22 at 3 17 00 PM

What seems to be the problem? Using Snapkit 4.0.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

netgfx picture netgfx  ·  3Comments

swiftli picture swiftli  ·  9Comments

semiwhale picture semiwhale  ·  3Comments

chengkaizone picture chengkaizone  ·  3Comments

MoShenGuo picture MoShenGuo  ·  4Comments