0
votes

I have the following view tree:

StackView
- axis: vertical
- alignment: fill
- distribution: fill
- spacing: 0
- constraints:
- - - trailing space to: Superview
- - - leading space to: Superview
- - - top space to: Superview
- - - subviews:
- - - - - UIView (name: VIEW_ONE)
- - - - - - - constraints:
- - - - - - - - - height: 60
- - - - - - - subviews:
- - - - - - - - - UIView (name: VIEW_TWO)
- - - - - - - - - - - constraints:
- - - - - - - - - - - - - align center Y to: Superview
- - - - - - - - - - - - - trailing space to: Superview
- - - - - - - - - - - - - leading space to: Superview
- - - - - - - - - - - - - height: 20

obs: the StackView is inside a UIView that occupies the entire screen

It all works fine until I try to set the VIEW_ONE's hidden state to true. The Xcode UI starts complaing that the VIEW_TWO:
- Need constraints for: Y position or height;
- Need constraints for: X position or width.

Why is that happening? I tried a lot of things to solve that problem, but nothing worked out =/


design

1
Can you show the design please? - iPeter
@iPeter, I have just updated the post :) - Augusto Carmo
Your stackView contains only one subview, why have you used stackView then. Your second view is a subview of your first view as I can see. - iPeter
My stackView actually contains many subviews. But I could simplify the problem I am having to that. I thought it would be simpler to use as an example. - Augusto Carmo
See, if you have only one view then no need to embed that to stackView, you can simply set its position by adding constraints to it. But if you have more than one view and you need to place all of them onto a certain position and with some spacings then you should be using stackView. - iPeter

1 Answers

0
votes

When you hide the view inside the stackView , it means from the stackView logic that you remove it , so it leaves the stackView ambiguous width and height instead of set hidden to true , you can make the height constraint's constant = 0 , with setting clipsToBounds = true