本文介绍了容器视图中均匀地空间的多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自动布局使我的生活困难。从理论上讲,这将是真正有用的,当我开机,但我似乎豁出去了所有的时间。

Auto Layout is making my life difficult. In theory, it was going to be really useful when I switched, but I seem to fight it all of the time.

我做了一个示范项目,试图找到帮助。有谁知道如何使视图之间的空间增大或每当视图大小均匀下降?

I've made a demo project to try to find help. Does anyone know how to make the spaces between views increase or decrease evenly whenever the view is resized?

下面三个标签(手动垂直间隔连):

Here are three labels (manually spaced vertically even):

我要的是让他们调整自己的间距(不是视图大小)均匀,当我转动。缺省情况下,顶视图和底视图朝向中心压扁:

What I want is for them to resize their spacing (not the view size) evenly when I rotate. By default, the top and bottom views squish towards the center:

推荐答案

所以,我的方法可以让你做到这一点接口生成器。你要做的就是打造'间隔的意见已设置为同样匹配的高度。然后加入顶部和底部约束标签(见截图)。

So my approach allows you to do this in interface builder. What you do is create 'spacer views' that you have set to match heights equally. Then add top and bottom constraints to the labels (see the screenshot).

更具体地讲,我对'间隔查看1'顶部约束与优先级较低的高度约束比1000上海华和高度等于所有其他间隔的意见。 间隔查看4'的底部空间制约上海华。每个标签都有各自的顶部和底部制约的最近的'隔离的意见。

More specifically, I have a top constraint on 'Spacer View 1' to superview with a height constraint of lower priority than 1000 and with Height Equals to all of the other 'spacer views'. 'Spacer View 4' has a bottom space constraint to superview. Each label has a respective top and bottom constraints to its nearest 'spacer views'.

请注意:请确保没有多余的顶部/在你的标签,以上海华底部空间的限制;只是那些以空间视图。因为顶部和底部的约束是对太空视图1'和'间隔View 4的这将是满足的。

Note: Be sure you DON'T have extra top/bottom space constraints on your labels to superview; just the ones to the 'space views'. This will be satisfiable since the top and bottom constraints are on 'Space View 1' and 'Spacer View 4' respectively.

咄1:我重复我的观点,只是把它在横向模式,所以你可以看到它的工作。

Duh 1: I duplicated my view and merely put it in landscape mode so you could see that it worked.

咄2:在间隔意见本来是透明的。

Duh 2: The 'spacer views' could have been transparent.

3咄:该方法可以应用于水平

Duh 3: This approach could be applied horizontally.

这篇关于容器视图中均匀地空间的多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:16