与scrollView相关的Autolayout问题

时间:2015-02-23 00:27:58

标签: ios xcode swift interface-builder autolayout

我已经实现了ScrollView。
我想在视图之间切换。
因为它是如此简单的UI内容,我只需要一个Controller并使用隐藏属性在两个视图之间切换。 此外,我想定位一些标签和视图。 但是我无法将它们居中,它们位于右侧太远。 我认为我的约束是正确的。 你知道如何解决这个问题吗?

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

根据你的布局我尝试创建类似的布局。

您需要做的是将容器视图添加为UIScrollView的SubView。

滚动视图的约束:

You need to set top,reading,trailing and Height constraints.

容器视图的约束:

You need to set leading,top,trailing and bottom constraints.
You need to set _Height Equally_ to scroll View.
You need to set _Width Equally_ to View.

对标签的约束:

1。)标签2约束:

You need to set **Center Horizontally and center Vertically**.

2。)标签1约束:

You need to set **Leading space**.

// I’ve set leading space: 10
You also need to set center Y to label 2.

3。)标签3约束:

You need to set **Trailing space**.

// I’ve set leading space: 10
You also need to set center Y to label 2.

图像视图的约束:

You need to set height,width and Vertical Space Constraints.
you also need to set center Horizontally to View.

enter image description here

希望这可以帮助您解决问题。