简体   繁体   English

与scrollView相关的Autolayout问题

[英]Autolayout issue related to scrollView

I have implemented a ScrollView. 我已经实现了ScrollView。
I want to switch between to Views. 我想在视图之间切换。
Because it's such simple UI stuff, I just take one Controller and use the hidden attribute to switch between the two views. 因为它是如此简单的UI东西,我只需要一个Controller并使用hidden属性在两个视图之间切换。 Furthermore, I want to position some labels and the views. 此外,我想定位一些标签和视图。 However I can't center them, they are positioned too far on the right side. 但是我无法居中,他们位于右侧太远。 I think my constraints are right. 我认为我的约束是正确的。 Do you know how to solve this issue? 你知道如何解决这个问题吗?

在此输入图像描述在此输入图像描述

According to your layout i've tried creating similar kind of layout. 根据你的布局,我尝试创建类似的布局。

What you need to do is add Container View as SubView of UIScrollView. 您需要做的是将Container View添加为UIScrollView的SubView。

Constraints to Scroll View: 滚动视图的约束:

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

Constraints to Container View: 容器视图的约束:

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.

Constraints to Label: 标签的约束:

1.) Label 2 Constraints: 1.)标签2约束:

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

2.) Label 1 Constraints: 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.) Label 3 Constraints: 3.)标签3约束:

You need to set **Trailing space**.

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

Constraints to Image View: 图像视图的约束:

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

在此输入图像描述

Hope this help you to solve your problem. 希望这可以帮助您解决问题。

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

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