UIStackView Unable to simultaneously satisfy constraints on squished hidden views
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This warning usually appears when a view inside a UIStackView is hidden, but some of its own constraints still insist that it keep a nonzero size. UIStackView tries to collapse hidden arranged subviews out of the layout, while your explicit constraints try to preserve space. The Auto Layout engine then has to break something, and you see the familiar unsatisfied-constraints log.
Understand What UIStackView Does With Hidden Arranged Subviews
A stack view treats arrangedSubviews differently from ordinary subviews. When an arranged subview becomes hidden, the stack view generally stops allocating normal layout space for it. The view still exists in the hierarchy, but the stack wants that area to collapse.
If the hidden view has a required height, width, or internal edge constraint that still demands room, the stack view and the hidden view are now pushing in opposite directions.
A Typical Failing Setup
This simplified example shows the pattern.
The stack view wants detailsView to collapse, but the explicit required height constraint says the view must remain 80 points tall. The warning is the layout engine telling you those rules cannot both win.
Deactivate Size Constraints When Hiding the View
The cleanest fix is often to toggle the conflicting constraint together with visibility.
This keeps the layout rules consistent. When the view is hidden, the stack is free to collapse it.
Remove the Arranged Subview When the View Is Truly Optional
If the view is not just temporarily hidden but structurally absent, remove it from the arranged subviews instead of keeping it hidden forever.
That removes the conflict entirely and is often the best choice for optional sections such as error banners, advanced settings panels, or empty-state content.
Be Careful With Nested Constraints
Sometimes the direct height constraint is not the problem. The warning can come from constraints inside the hidden view, such as top and bottom anchors, image aspect-ratio constraints, or a label container with required padding.
In those cases, hiding the outer view is not enough because the internal required constraints still describe a layout the stack can no longer satisfy. A wrapper view can help.
Use a Wrapper View for Complex Content
If a content block has many internal rules, place it inside a container view and add the container as the arranged subview. Then hide or remove the container instead of the inner content.
This gives the stack view one object to collapse while the inner layout remains self-contained when visible.
Lower Priorities When Appropriate
Not every size rule needs to be required. If a height or spacing constraint is only a preference, lower its priority so Auto Layout can relax it during collapse.
Do this only when the rule is genuinely negotiable. Lowering priorities to silence warnings without understanding the layout usually creates a fragile interface.
Debug the Actual Broken Constraint
When Xcode prints a long constraint log, focus on the constraints attached to the hidden arranged subview and any explicit dimension constraints. That is almost always where the contradiction lives.
A useful discipline is to ask one concrete question: if this view is hidden, which constraints still require it to occupy space. Once you identify those, the fix is usually straightforward.
Common Pitfalls
- Hiding an arranged subview but leaving a required height or width constraint active.
- Looking only at the stack view and missing constraints inside the hidden view's subtree.
- Lowering priorities blindly instead of removing the actual contradiction.
- Keeping permanently optional sections hidden instead of removing them from arranged subviews.
- Assuming
isHiddenautomatically makes every related constraint harmless.
Summary
- '
UIStackViewwants hidden arranged subviews to collapse out of layout space.' - Warnings appear when other required constraints still force the hidden view to keep a size.
- The usual fix is to deactivate those size constraints when hiding the view.
- For truly optional content, remove the arranged subview completely.
- Wrapper views and careful priority choices help with more complex nested layouts.
Related reading
- UIStatusBarStyle not working in Swift
- UITableView - change section header color
- UITableView - scroll to the top
- UITableView Add content offset at top
- UITableView Cell selected Color?
- UITableView clear background
- UITableView disable swipe to delete, but still have delete in Edit mode?
- UITableView dynamic cell heights only correct after some scrolling
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.