Question is very similar to this but I am interesting in what happen when UIView change isHidden
value.
For Example:
| | |
-[ViewA]-[ViewB]-[ViewC]-
| | |
at draft:
[X]
-> views
|
and -
-> constraints
What is happen when: ViewB.isHidden = true
How to correct handle showing/hiding subviews (without UIStackView
) in code? Should I manually set constraints to active/inactive?
Normally, hiding a view (by setting isHidden
) has no effect on layout. Hidden views participate in layout. Any constraints connected to the view are still enforced. The area occupied by the now-hidden view is still reserved for it.
This is useful because it allows you to use hidden views as “spacers” to create layouts (in Interface Builder) that you cannot otherwise create. (In code, you can use UILayoutGuide
s instead of hidden views, but IB doesn't support creating layout guides.)
UIStackView
is different from other views. UIStackView
observes the isHidden
property of each of its arranged subviews. When an arranged subview's isHidden
changes, the UIStackView
updates constraints to make or remove the area used by that subview.
No other view does what UIStackView
does, so no other view adjusts the layout of its subviews when they become hidden or visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With