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.