When using size class-specific constraints, some items in a stack view are placed outside on re-install

14 Views Asked by At

So let's say you're using Xcode's storyboard and you're setting up size class constraints so you can have a unique layout for portrait and landscape mode. Your screen has a stack view with six elements in it. When the screen swaps to landscape mode, two of these items are uninstalled because they don't fit comfortably on the screen. When you switch back to portrait mode, they're reinstalled. But because the rest of the stack view (including a button that goes BELOW the toggled objects, and a text view that goes ABOVE them) is already loaded when these two objects are re-installed, they're loaded outside of the stack view and pin themselves on top of it and apply their constraints afterword. This gives me a result like so:

enter image description here

Portrait mode (start)

enter image description here

Landscape mode

enter image description here

Portrait mode (re-activated after landscape)

I thought maybe I could fix this by changing the priority of some constraints, but I don't have any that control their position in the stack-- at least not ones that I added and can therefore edit. I can't think of a safe or adequate way to add any that would act this way.

If you'd like me to share a storyboard file, I'd be happy to, but I can't for the life of me find out how. Any pointers for that would be appreciated also.

1

There are 1 best solutions below

0
Juliana Nielson On

After tinkering for a while I've found that if you, instead of uninstalling the objects, add constraints that set their height to 0, you essentially get the same effect as before but without this issue. I've also found most, if not all, UI objects have a property named "Hidden". You can add size class variations to these to hide the objects while on a different screen type for a different portrait-to-landscape visual transition. I'm not sure if this is the proper answer, but it does work for now.