ParentView contains ChildView1 and ChildView2. These subviews are of different heights.
ChildView1 is taller than ChildView2. Only one subview is shown, e.g., if ChildView1 is visible then ChildView2 is hidden. Both ChildView1 and ChildView2 use custom XIBs.
Both subviews "drive" the height of ParentView, that is the AutoLayout constraints are wired such that ParentView is as tall as ChildView1 or ChildView2, and no taller.
The problem is hiding ChildView1 and showing ChildView2 does not "shrink" ParentView to match the height of ChildView2. It remains at the height of the taller subview, ChildView1.
Calling sizeToFit()
and setNeedsLayout()
does not change things.
How to force ParentView to match ChildView2's height when ChildView1 is hidden?