简体   繁体   English

如何在滚动视图中为垂直堆栈视图设置自动布局约束

[英]How to set up autolayout constraints for vertical Stack View in Scroll View

I have the following setup, which I can't get properly to work with auto-layout: 我有以下设置,无法正确使用自动布局:

Scroll View, which should take the whole screen
 |_ Stack View, which should take the whole size of the Scroll View
     |_ View 1 with a predefined height of 200
     |_ View 2 with a flexible height defined by content, but minimum 300
     |_ View 3 with a predefined  height of 500

I tried the following yet: 我尝试了以下方法:

  1. Scroll View 滚动视图
    • Set top, bottom, leading and trailing alignment to superview 将顶部,底部,前导和尾随对齐设置为超级视图
  2. Stack View 堆栈视图
    • Set top, bottom, leading and trailing alignment to superview (Scroll View) 将顶部,底部,前导和尾随对齐方式设置为超级视图(滚动视图)
    • Set equal width to superview (Scroll View) 设置相等的宽度到超级视图(滚动视图)
    • Set equal height to superview (Scroll View) with priority 250 将优先级250设置为与超级视图(滚动视图)相等的高度
  3. The 3 Views inside Stack View 堆栈视图中的3个视图
    • Define height = 200 for View1 and height = 500 for View3 为View1定义高度= 200,为View3定义高度= 500
    • Define height >= 300 for View2 为View2定义高度> = 300

And I get: 我得到:

  • an error in IB: Inequality Constraint Ambiguity for the View2 IB中的错误:View2的不平等约束歧义
  • if I launch and scroll I get additional spacing at the top and the bottom (see the red areas on the top and bottom in the simulator screenshots) 如果我启动并滚动,则会在顶部和底部获得更多间距(请参见模拟器屏幕快照中顶部和底部的红色区域)

Please see the screenshots: 请查看屏幕截图: 滚动视图的约束 堆栈视图的约束 预定义的高度限制 灵活的高度限制 顶部有额外空间 底部额外的空间

在此处输入图片说明

Change the top, bottom, leading and trailing alignment to SafeArea 将顶部,底部,前导和尾随对齐方式更改为SafeArea

Because content view always inside the SafeArea. 因为内容视图始终在SafeArea中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM