代码之家  ›  专栏  ›  技术社区  ›  FrankZp

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

  •  1
  • FrankZp  · 技术社区  · 6 年前

    我有以下设置,无法正确使用自动布局:

    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
    

    我已经试过了:

    1. 滚动视图
      • 将顶部、底部、前导和尾随对齐设置为超级视图
    2. 堆栈视图
      • 将顶部、底部、前导和尾随对齐设置为超级视图(滚动视图)
      • 将“等宽”设置为“超级视图”(滚动视图)
      • 将“等高”设置为“超级视图”(滚动视图),优先级为250
    3. 堆栈视图中的3个视图
      • 定义View1的height=200和View3的height=500
      • 定义视图2的高度>=300

    我得到:

    • IB中的一个错误:View2的不等式约束模糊性
    • 如果我启动并滚动,我会在顶部和底部获得额外的间隔(请参见模拟器屏幕截图中顶部和底部的红色区域)

    请看截图: Constraints for Scroll View Constraints for Stack View Predefined height constraint Flexible height constraint Additional space at the top Additional space at the bottom

    1 回复  |  直到 6 年前
        1
  •  0
  •   Vadivel Murugan    6 年前

    enter image description here

    将顶部、底部、前导和尾随对齐方式更改为 安全区

    因为内容视图总是在安全区域内。