Nested UIStackViews Broken Constraints

后端 未结 7 778
故里飘歌
故里飘歌 2021-01-31 02:59

I have a complex view hierarchy, built in Interface Builder, with nested UIStackViews. I get \"unsatisfiable constraints\" notices every time I hide some of my inner stackviews.

7条回答
  •  情书的邮戳
    2021-01-31 03:41

    This is a known problem with hiding nested stack views.

    There are essentially 3 solutions to this problem:

    1. Change the spacing to 0, but then you'll need to remember the previous spacing value.
    2. Call innerStackView.removeFromSuperview(), but then you'll need to remember where to insert the stack view.
    3. Wrap the stack view in a UIView with at least one 999 constraint. E.g. top@1000, leading@1000, trailing@1000, bottom@999.

    The 3rd option is the best in my opinion. For more information about this problem, why it happens, the different solutions, and how to implement solution 3, see my answer to a similar question.

提交回复
热议问题