如何在Swift

时间:2017-07-25 04:31:37

标签: ios swift xcode uiview uiscrollview

我使用swift构建应用程序。我想使用storyboard向我的视图控制器添加一些内容。

我已将所有内容放在scrollview中并设置特定高度,但是当我运行应用程序时,scrollview的设置总是比视图底部的按钮长

我希望滚动视图在按钮

之后立即停止

请帮助我如何解决这个问题

谢谢

this is the top of the view

after scrolling (see the blank content after button submit)

滚动后

为了您的信息,请忽略评论家和评论家之间的空格。并提交按钮,因为它们之间实际上有UITextView但不可见(仍尝试添加一些边框)

这些是我的故事板预览

storyboard 1

storyboard 2

3 个答案:

答案 0 :(得分:8)

1)ScrollView Contraints

enter image description here

2)ScrollView - > contentView约束滚动视图与上图相同

3)现在ContentView宽度和高度约束到主视图[嵌入ScrollView的SuperView]和约束如下。

4)现在点击EqualWidth查看[顶部的第三个约束]并按照步骤6进行编辑

enter image description here

5)contentView Width Contraint

enter image description here

6)ContentView高度约束//设置优先级[必须]。在这里你需要更改菜单中的第一项和第二项,如第一项所示 - ContentView.Height和第二项 - View.height并将优先级设置为250之后,沿着contentView在故事板中出现虚线

enter image description here

7)现在在contentView中添加像[UIView,labels,textfields]这样的内容,并将约束作为Top upperMost视图顶部空间添加到contentView [就像我有] DoubleRight imageView

enter image description here

我的DoubleRight imageView的

和约束是

enter image description here

寻找顶部空间边距给出顶部空间20点

和你需要在ContentView中添加的最后一项相同,就像我有uiView

一样

enter image description here

将这个相应视图的底部空间添加到superView [ContentView],我的约束是:

enter image description here

在您初始化所有这些步骤后,结果将按照预期的每个屏幕尺寸进行,无需为屏幕尺寸更改高度

注意: - [所有视图必须以顶部和底部参数相互连接]

像Flow一样

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 

使用uiView,uiimageViews必须修复它们的高度

答案 1 :(得分:0)

可能有所帮助

your_scrollView.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
your_scrollView.contentSize = CGSize(width: 375, height: 1000) // You can set height, whatever you want.

答案 2 :(得分:0)

您可以尝试:

   your_scrollView.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
   your_scrollView.contentSize = CGSize(width: 375, height: self.view.frame.size.hight)