简体   繁体   English

你知道为什么滚动视图中的堆栈视图不适合模拟器吗?

[英]Do you know why stack view in scroll view doesn't fit on simulator?

hello every one basically I want to fit stack view in scroll view in my Xcode design it's ok, and I have not an error but unfortunately in simulator really different about design, and here is my stack view and scroll view constraints and also I bring the result in simulator:大家好,基本上我想在我的 Xcode 设计中将堆栈视图放入滚动视图中,这没关系,我没有错误,但不幸的是在模拟器中的设计确实不同,这是我的堆栈视图和滚动视图约束,我也带来了结果模拟器:

在此处输入图像描述

and also this is my one of content constraints that all of view like this are horizontally and vertically in container alignment:这也是我的内容限制之一,所有像这样的视图在容器 alignment 中都是水平和垂直的:

在此处输入图像描述

could you tel me what's your opinion to solve this matter?你能告诉我你对解决这个问题有什么看法吗?

The reason why the each content is piling up like the result in simulator is because scroll view unable to calculate content height and also each content constraint has the center point set up to be the same as another (or the same as stack center)每个内容像模拟器中的结果一样堆积的原因是因为滚动视图无法计算内容高度,并且每个内容约束的中心点设置为与另一个相同(或与堆栈中心相同)

What you can do to fix the UI is你可以做些什么来修复 UI

  1. Set the first content top constraint to stack view top将第一个内容顶部约束设置为堆栈视图顶部
  2. Set the next content top constraint to last item bottom将下一个内容顶部约束设置为最后一项底部
  3. Set the last item bottom constraint to stack view bottom将最后一项底部约束设置为堆栈视图底部
  4. Set each item height and width设置每个项目的高度和宽度

So in summary, each view should have this constraint:所以总而言之,每个视图都应该有这个约束:

  1. top constraint equal (or add some margin) to previous view bottom constraint, except for first view where it should be equal to stack view top顶部约束等于(或添加一些边距)到前一个视图底部约束,除了第一个视图应该等于堆栈视图顶部
  2. bottom constraint equal (or add some margin) to next view top constraint, except for last view where it should be equal to stack view bottom底部约束等于(或添加一些边距)到下一个视图顶部约束,除了最后一个视图应该等于堆栈视图底部
  3. height constraint高度约束
  4. width constraint宽度约束
  5. remove center x and y constraint移除中心 x 和 y 约束

That way scroll view can calculate its content height这样滚动视图可以计算其内容高度

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

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