Search code examples
iosuiscrollviewuistackviewsafearea

UIScrollView with UIStackView which resizes to fullfill the screen height


No code because everything is placed in xib.

Structure: UIScrollView contains UIView (UIScrollView Scrollable Content Size Ambiguity) which contains UIStackView which contains a list of subviews. All the UIStackView subviews have fixed height except of one which has "minimal height" only and I need to stretch this view to make UIStackView fullfilling all available height if necessary. If UIStackView is very big then UIScrollView should scroll UIStackView.

Tried a lot of combinations but the only view which should stretch or collapse has unpredictable height. In better case it works as expected but UIScrollView content fully ignores safe area (becomes larger than expected).

Did somebody faced this problem?

Edited

It is a view controller inside xib, loading/presenting modally. A link to xib


Solution

  • Found a weird solution:

    • disable safe area for the root view
    • enable safe area for scroll view (which is is inserted directly in the root view)
    • setup constraints like here (leading, trailing, top, bottom, equal width, equal height with low priority) with one difference - scroll view's root view height should be equal not to superview height but to safe area height

    But maybe someone can suggest a better solution