I have a ViewController with a UIStackView aligned to its parent container with some margins (Leading, Trailing, Top Space, Bottom) and Vertical Axis. UIStackView is set to Alignment "Fill" and Distribution "Equal Spacing". Inside the UIStackView, I have three UIScrollViews as children. Each UIScrollView has a UIView with some controls inside.
If I set the UIStackView in IB to Distribution "Fill" and if I set the second UIScrollView's Content Hugging Priority to 200, and leave the first and third UIScrollViews to their default of 250, I see that the second UIScrollView is stretched properly to fill the empty space, as expected and desired.
However, I want to set the UIStackView to Distribution "Equal Spacing" by default in IB, and in code, when the user taps one of the UIScrollViews, I want the tapped UIScrollView to expand and fill up the rest of the space. So I added the following code on tapping a UIScrollView (in order to set that tapped UIScrollView's CHP to a lower value than its peers):
scrollViewToExpand.setContentHuggingPriority(UILayoutPriority(rawValue: 200), for: .vertical)
stackView.distribution = .fill
However, the first UIScrollView always gets stretched and the second and third UIScrollViews never get stretched.
Each descendant UIView of each UIScrollView is set to trailing/leading/bottom/top matching SuperView and equal widths.
What am I doing wrong?