Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens with constraints when a view is begin to be hidden?

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?

like image 798
Kamil Harasimowicz Avatar asked Sep 21 '25 13:09

Kamil Harasimowicz


1 Answers

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 UILayoutGuides 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.

like image 107
rob mayoff Avatar answered Sep 23 '25 07:09

rob mayoff