Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interface Builder is collapsing vertical stack view horizontally and back after each action

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:

enter image description here

Here is the same view, just after changing literally anything:

enter image description here

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.

like image 305
Can Poyrazoğlu Avatar asked Jan 04 '18 11:01

Can Poyrazoğlu


People also ask

How do I change the stack view height?

'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).

What is stackView alignment?

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.

When should I use stackView?

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.

How do I use stack view auto layout?

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.


1 Answers

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:

enter image description here

enter image description here

Though I still don't know why it was collapsing the whole stack view after each action.

However, it fixed the issue.

like image 180
Can Poyrazoğlu Avatar answered Sep 22 '22 21:09

Can Poyrazoğlu