简体   繁体   English

UIStoryBoard Auto Layout在UIScrollView内嵌入UIStackView

[英]UIStoryBoard Auto Layout embed UIStackView inside UIScrollView

I'm having a problem design my ViewController which contain a some Label and a ImageView. 我在设计包含一些Label和ImageView的ViewController时遇到问题。 I have embed them in a StackView. 我已经将它们嵌入StackView中。 My objective is to place a StackView inside a ScrollView so that my content will be scrollable if the content is longer then the screen height 我的目标是将StackView放在ScrollView内,以便如果内容长于屏幕高度,则我的内容可以滚动

So basically what I have done is 所以基本上我要做的是

1 - Place a UIScrollView in a scene. 1-将UIScrollView放置在场景中。 Pin the scroll view to its superview without margins. 将滚动视图固定在其上,且没有边距。

2 - Place a UIStackView inside the scroll view. 2-将UIStackView放置在滚动视图中。 Pin all sides of the stack view to the scroll view without margins (yes this is counterintuitive). 将堆栈视图的所有边固定到滚动视图,且没有空白(是的,这是违反直觉的)。

3 - Vertical scrolling: Add an equal widths constraint between the scroll view and the stack view 3-垂直滚动:在滚动视图和堆栈视图之间添加相等的宽度约束

Here is my setting in storyboard 这是我在情节提要中的设置

在此处输入图片说明

But I'm getting this red warning constrains. 但是我得到了这个红色警告约束。 Anyone know how to fix this? 有人知道怎么修这个东西吗? Maythanks Maythanks

在此处输入图片说明

Try example given at this Link It is using following steps 尝试在此链接中给出的示例它正在使用以下步骤

  1. Create a UIScrollView, and set its constraints. 创建一个UIScrollView,并设置其约束。
  2. Add a UIStackView to the UIScrollView 将UIStackView添加到UIScrollView
  3. Set the constraints: Leading, Trailing, Top & Bottom should be equal to the ones from UIScrollView 设置约束:前导,尾随,顶部和底部应与UIScrollView中的约束相同
  4. Set up an equal Width constraint between the UIStackView and UIScrollView. 在UIStackView和UIScrollView之间设置相等的Width约束。
  5. Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the UIStackView 在UIStackView上设置Axis = Vertical,Alignment = Fill,Distribution = Equal Spacing和Spacing = 0

    https://github.com/ar-juan/uistackview-in-uiscrollview https://github.com/ar-juan/uistackview-in-uiscrollview

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

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