I have a viewController (A) with a stackView in it. The stackView has constraints for leading, trailing and bottom.
Inside the stackView, I add a UIViewContainer, that embeds a UIViewController (B). B contains a UIView, with a fixed height, and top, bottom, leading and trailing constraints.
When I launch the app, the stackView has a height of 0, as if the contained viewController had no constraints.
Is there a way to have the stackView size be correct without adding a constraint for the stackView height ?
Thanks
What you describe here could very well be the issue — every view’s constraints must be unambiguous. Otherwise, runtime behaviour could be unpredictable. For example, if you were creating a plain rectangular view, you could:The stackView has constraints for leading, trailing and bottom.
Give it an explicit width, height, x, and y positions, or
Constrain it to the top, bottom, leading, and trailing edges of the superview.
Now, imagine your plain rectangle is defined by with constraints relative to its superview (the second option above). What if you were to remove the constraint at the top? What would happen? How tall is the view? It could be super tall beyond the top of the device’s canvas, or it could be super short.
So I think you may just need to add a constraint from the the top of the stack view to its parent.
However, I could be wrong, since I can’t see the app. You can try and confirm your theory in a few ways:
At runtime, do you see any error messages in the Xcode console about ambiguous constraints?
If you take a look in the view debugger, does the stack view actually have a height of zero, or is something else going on?