floriankugler / FLKAutoLayout

UIView category which makes it easy to create layout constraints in code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting an existing NSLayoutConstraint

jordim opened this issue · comments

Working with a graph bar I needed to update a constant to make an UIViewAnimation. FLKAutoLayout is amazing with adding but it lacks support for get or update constraints.

Would be nice to be able to get an existing constraint by type just for update their constant or just maybe for delete and add again with new values.

I've tried one snipped I found (not mine) http://stackoverflow.com/questions/13857115/getting-an-existing-nslayoutconstraint-for-the-width and it works perfectly.

Awesome library anyway!!!

I agree that it would be nice to have a convenient way to retrieve existing constraints. However, the problem with the method described in the stack overflow question is, that it can also be ambiguous if there are multiple constraints on this view which are associated with a specific layout attribute. It would be nice to have a non ambiguous way to do this.

What I would do at the moment is to hold on to the constraint which you want to modify later. All methods in FLKAutoLayout return an array of constraints which were created. So if you want to modify a certain constraint later, you can e.g. assign it to an instance variable to have access to it later. Probably you would want to create this particular constraint isolated from the rest, so that you will get back an array with only one constraint.

I ended up doing what you said but without constrainWidthToView constraint because multiplier is a readonly property. I used some maths with constrainWidth instead.

I will think about this, maybe there is nice solution to this problem... let's see :)

@jordim I create this category to update constraints easily after creation https://github.com/damienromito/UIView-UpdateAutoLayoutConstraints.
@dkduck if you want you can include the method in your Lib