【问题标题】:Autolayout issue related to scrollView与 scrollView 相关的自动布局问题
【发布时间】:2015-02-23 00:27:58
【问题描述】:

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

【问题讨论】:

  • 无法查看您的图像。可以再检查一遍吗?
  • 我没有足够的声誉,这就是为什么我在“.png”之前添加了一个空格标签。只需删除此空间,这两个链接就会起作用。

标签: ios xcode swift interface-builder autolayout


【解决方案1】:

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

您需要做的是添加 Container View 作为 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.

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

【讨论】:

    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2010-12-04
    相关资源
    最近更新 更多