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

Added ability to create disabled constraints from code #533

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

dev4dev
Copy link

@dev4dev dev4dev commented Aug 20, 2018

Hello, here is a feature to create disabled constraints along the base layout. This is required sometimes when layout requires changes initiated by disabling/enabling some sets of constraints. Without that there will be layout errors because of constraints conflicts.

view.snp.makeConstraints { make in
    make.edges.equalToSuperview()
    make.height.equalTo(400).disabled()
}

I didn't find the way to achieve that with already existed methods, as a result, added this method.

@kmcginnes
Copy link

The way to create inactive constraints is not straightforward, but does exist. You must create the constraint in a prepareConstraints call and store the constraint in your class so it can be enabled or disabled at will

let label = UILabel()
addSubview(label)

var savedConstraint: Constraint?
label.snp.prepareConstraint { make in
  savedConstraint = make.centerY.equalToSuperview().constraint
}

savedConstraint?.deactivate()
savedConstraint?.activate()

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

Successfully merging this pull request may close these issues.

None yet

2 participants