I am designing a view controller in Interface Builder and have a stack view. After any action (e.g. moving any object a tiny bit, or changing a constraint by 1px) the whole stack view collapses horizontally, messing up all the layout. Then, when I take any other action (e.g. change another constraint, or even the same one, doesn't matter) it gets back to its original correct layout.
Here is a screenshot of the correct layout:
Here is the same view, just after changing literally anything:
When I change anything again, it gets fixed (back to correct layout), and gets messed up again when I change something else, going forever like that. There aren't any autolayout issues in the inspector. Also, after this problem started, I've set all views' hugging and compression resistance constraints to 1000, but no avail. What might be causing this? I am on Xcode 9.2.
'Fill proportionally' distribution type works with intrinsic content size. So if our vertical stack(height say 600) view has 2 views, ViewA (intrinsic content height 200) and ViewB(intrinsic content height 100), the stack view will size them to ViewA(height 400) and ViewB(height 200).
A layout where the stack view aligns the center of its arranged views with its center along its axis. case leading. A layout for vertical stacks where the stack view aligns the leading edge of its arranged views along its leading edge.
Best use of stack view is that if you want to set multiple controls allinged vertically or horizontally to each other you just add all of them in stack view. stackview will handle its allignment you just need to give frame contraints to stackView.
Views and Constraints Begin by laying out the name rows in Interface Builder. Position the label and text field in their correct relative positions, select them both, and then click the Editor > Embed In > Stack View menu item. This creates a horizontal stack view for the row.
Right after posting this, I've noticed something:
If I give a preferred explicit width (anything greater than zero, doesn't matter if 1 or 10000) the problem goes away:
Though I still don't know why it was collapsing the whole stack view after each action.
However, it fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With