问题描述
我正在使用 swift 构建应用程序.我想使用情节提要向我的视图控制器添加一些内容.
我已经把所有东西都放在了滚动视图中并设置了特定的高度,但是当我运行应用程序时,滚动视图总是设置得比视图底部的按钮长
我希望滚动视图在按钮之后立即停止
请帮我解决这个问题
谢谢
滚动后
为了您的信息,请忽略 'critics' 和提交按钮之间的空白,因为实际上它们之间有 UITextView 但不可见(仍然尝试添加一些边框)
这些是我的故事板预览
1) ScrollView Contraints
2) ScrollView -> contentView 滚动视图的约束与上图相同
3) 现在 ContentView 的宽度和高度约束到主视图[嵌入了 ScrollView 的 SuperView] 和约束如下.
4) 现在单击 EqualWidth 以查看 [从顶部开始的第三个约束] 并按照步骤 6 进行编辑
5) contentView 宽度约束
6) ContentView 高度约束//设置优先级 [必须] .在这里,您需要将菜单中的第一项和第二项更改为如图所示 First as - ContentView.Height 和第二个 as - View.height 并将优先级设置为 250 在此之后,情节提要中将出现一条虚线沿 contentView
7) 现在在 contentView 中添加 [UIView, labels, textfields] 之类的内容,并将约束作为 Top upperMost 视图顶部空间添加到 contentView [就像我一样]DoubleRight imageView
我的 DoubleRight imageView 的约束是
在给定顶部空间 20 点的情况下查找顶部空间边距
同样你需要为你将添加到 ContentView 中的最后一个项目做同样的事情,就像我有 uiView 一样
将各自视图的底部空间添加到您的 superView[ContentView] 中,我的约束是:
在您初始化所有这些步骤后,每个屏幕尺寸的结果都将与预期一样,无需额外更改屏幕尺寸的高度
注意:-[所有视图必须通过 top 和 bottom 参数相互连接]
像 Flow 一样
View1 - 顶部到 contentView,底部到 View2View2 - 从顶部到 View1,从底部到 view3View3 [Last view] - 顶部到 View2 和底部到 contentView,如图所示
使用uiView,uiimageViews的高度必须是固定的
I'm using swift to build an application. I want to add some content to my view controller using storyboard.
I already put everything inside the scrollview and set the specific height, but however when I run the application, the scrollview always set longer than the button in the bottom of the view
I want the scroll view stop right after the button
Please kindly help me how to solve this problem
thank you
after scrolling
for your information, please ignore the white space between 'critics' and submit button, because actually there's UITextView between them but not visible (still try to add some border)
these are my storyboard preview
1) ScrollView Contraints
2) ScrollView -> contentView Constraints to scroll View same as above image
3) now ContentView width and Height Constraints to main View [SuperView in which ScrollView is embedded] and constraints will be as follows.
4) now click on the EqualWidth to View [Third constraint from top]and edit it as in step 6
5) contentView Width Contraint
6) ContentView Height Constraint // set priority [must] . here you need to change the first item and second item in the menu to as shown First as - ContentView.Height and second as - View.height and set priority to 250 after this a dotted line will appear in storyboard along the contentView
7) now add the content like [UIView, labels, textfields] in contentView and add constraints as Top upperMost view top space to contentView [like I have]DoubleRight imageView
and constraints for my DoubleRight imageView are
look for the Top space margin its given a top space 20 points
and same you need to do for the last item you will be adding in ContentView like I have uiView
add bottom space from this respective view to your superView[ContentView] and my constraints are:
after you had initialed all these steps results will be as Expected for every Screen size no need to change height additionally for screen sizes
Note : - [all the views must be connected to each other with top and bottom parameter]
like Flow will be
View1 - top to contentView and bottom to View2
View2 - top to View1 and bottom to view3
View3 [Last view] - top to View2 and bottom to contentView as shown
using uiView, uiimageViews their heights must be fixed
这篇关于如何在 Swift 中设置 UIScrollView 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!