Is there a way to access the priority of constraints placed by UIStackView?
Asked Answered
N

1

7

I'm getting "Unable to simultaneously satisfy constraints" when using UIStackView's .hidden property.

I know it's because since I set Distribution to "fill equally" and the Spacing to 1 and then hide the UIStackView it tries to set its height to zero in order to animate the hiding it out so it will have several competing priority 1000 constrains creating the aforementioned warning.

I could solve the issue and resolve the warning if I could access the spacing constrains created by the UIStackView whose priorities are automatically set to 1000.

If I could somehow find a way to reduce those priorities to 999 so that the hiding height priority wins I could then avoid the warning.

So my question is is there a way to find the spacing constrains created by the UIStackView that come form the StackView's definition in the storyboard and assign a priority of 999?

Sort of like: for all constrains in a stackview { if constrain is a spacing type { set constrain priority to 999 } } or some other sort of algorithm.

Nonunionism answered 24/1, 2016 at 6:13 Comment(5)
I can't believe Apple will allow such thing :) are you sure that is the reason? Maybe it's preferred to change distribution and then set the hidden instead of messing with the inner constraintsLynelllynelle
Yes I'm sure that is the reason. I have checked it manually and the cause for the warning has been discussed and tested here before. The whole purpose of UIStackView is to make is easy to do automatic layout but if when you hide stacks you get the warning then it defeats the purpose of it being quick and easy for stacks that need to be hidden.Nonunionism
Thanks it's news for me, and what about changing the stack properties and then hide it?Lynelllynelle
That's exactly what I'm asking. I'm asking how to access properties that UIStackView created by looping through them somehow so I can change the priorities of the spacing constrains.Nonunionism
What about hiding all the components in the stackview?Modal
C
0

The priority on the spacing is based on the following: enter image description here

You can try changing any of these to avoid the warning. Take at look at Apple's documentation on the .spacing property of a stack view.

Calm answered 24/9, 2018 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.