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

Updating Constraint contant? #63

Closed
nickvelloff opened this issue Mar 26, 2015 · 5 comments
Closed

Updating Constraint contant? #63

nickvelloff opened this issue Mar 26, 2015 · 5 comments

Comments

@nickvelloff
Copy link

If I hang onto a constraint like:

var leftConstraint: Constraint?
let padding = UIEdgeInsetsMake(107, 0, 0, 0)
     draftsSiteManagement?.snp_makeConstraints { make in
            make.size.equalTo(self.view).with.insets(padding)
            make.top.equalTo(107)
            self.leftConstraint = make.left.equalTo(self.view.snp_right)
        }
}

How would I update the constant later?

@robertjpayne
Copy link
Member

Define how you would like to update said constraint? Are you looking to just update the "constant" or also re-assign the LHS/RHS?

If you strictly say want to update that 107 to maybe 40 or something you would just need to:

snp_updateConstraints { make in
    make.top.equalTo(40)
}

@nickvelloff
Copy link
Author

Thanks for responding.
I would like to update the self.leftConstraint constant such that left is now = self.view.snp_left, instead of right.
The real goal is to animate draftsSiteManagement from where is off screen to 0 (on screen).
Basically like I would do with a standard NSLayoutConstraint constraint.constant = 5

@nickvelloff
Copy link
Author

After reading your other response to my other question I think I'm not approaching this properly.
I probably need to uninstall the constraint and apply a new one and layoutIfNeeded() in an animation block.

@robertjpayne
Copy link
Member

@nickvelloff it's important to note there are a couple parts to a constraint. Remember the constant is strictly the offset value of the constraint. Constraints are formulated as such:

(LHS) (RELATION) (RHS)? * (MULTIPLIER) + (CONSTANT)

The RHS can be nil, in cases where you do an equalTo(<non-view-value>) you are actually essentially doing: equalTo(nil).offset(<non-view-value>).

So yes in your particular case you are altering the LHS/RHS of the constraint and thus need a new one.

@nickvelloff
Copy link
Author

I was confusing the meaning of self.view.snp_right with it evaluating that value and using it as a <non-view-value> constant. Newbie mistake, thanks for the clarification.

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

2 participants