Is there a way to get the constant ?
Closed this issue · 6 comments
A constraint has a multiplier and a constant
is there a way to find what the value of the constant is ?
One simplification of KeepLayout is, that every Attribute has only one value, which is then used either as constant or multiplier, but an Attribute never uses both. The value you assign to .equal
, .min
or .max
are then used based on the kind of the Attribute:
- Constant Attributes (backed by
KeepConstantAttribute
class): Width, Height, Insets, Offsets, Alignments. These always have multiplier one. - Multiplier Attributes (backed by `` class): Width To, Height To, Aspect Ratio, Center. These always have constant zero.
You can always obtain the current value using getters:
CGFloat widthConstant = view.keepWidth.equal;
CGFloat centerXMultiplier = view.keepHorizontalCenter.equal;
Is this what you meant?
yes indeed this is what i meant.
on another issue -
if there are constraints on a view given by storyboard or xib, and i add a keeplayout constraint that turns out to be conflicting, who wins ?
Glad to help. When there is a conflict, it’s on the Auto Layout engine to decide, which constraint to break. From my experience, it’s often the latest added constraint.
Martin
Sent from my iPhone
On 19 Dec 2014, at 12:28, pikaboo notifications@github.com wrote:
yes indeed this is what i meant.
on another issue -
if there are constraints on a view given by storyboard or xib, and i add a keeplayout constraint that turns out to be conflicting, who wins ?—
Reply to this email directly or view it on GitHub.
One thing to notice, is that I’m using complex numbers for the values of .equal
, .min
and .max
. This means, that direct comparison may not work as you think. The complex number includes the priority, which means:
view.keepWidth.equal = 100; // Set to 100, but defaults to Required priority.
if (view.keepWidth.equal == 100) ... // False !!!
if (view.keepWidth.equal == 100+keepRequired) ... // True
CGFloat width = view.keepWidth.equal; // Cast to plain number.
if (width == 100) ... // True
This is not very intuitive, but reading the values is not the primary use and it’s worth the syntax for setting :)
would it be possible for you to write it in the documentation ?
The reason that i am asking is that i usually want to animate constraints relative to previous constraint
meaning [self.view keepAnimatedWithDuration:0.25 layout:^{
self.someButton.width += some value;
}];
I want to know the correct syntax to do that, without my having to get the original constant it had
Your code will work OK.
The +=
operator takes the existing value (complex) and adds some value (real), but complex + real = complex, so imaginary part is preserved.
In other words: +=
increases the value, but preserves the priority. The problem I mentioned is mostly with comparisons.