汽车布局比例距离的限制 [英] Proportional distance constraints in auto layout

查看:131
本文介绍了汽车布局比例距离的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够实现与自动布局的意见所需的布局> iOS6的。

I am not able to achieve the desired layout of the views with the auto layout in >iOS6.

我有UIView1和UIView3其固定在父视图(相应的TopSpaceToSuperview,BottomSpaceToSuperView和fixedHeight固定高度),他们的行为时,父视图设置高度预期。

I have UIView1 and UIView3 which are fixed to the parent view (correspondingly with the TopSpaceToSuperview, BottomSpaceToSuperView and FixedHeight) and they behave as expected when the parent view changes the height.

我要在IB的UIView2指定的约束,如果我希望它保持它的兄弟姐妹(UIView1和UIView3)当父视图的变化高度同比例的距离? (如所显示的图像中)

Which constraints should I specify in the IB for the UIView2 if I want it to maintain the same proportional distance to its siblings (UIView1 and UIView3) when the parent view changes the height? (as displayed in the image)

推荐答案

要做到这一点的方法是使用你的意见之间无形的间隔的意见。

The way to do this is to use invisible "spacer" views between your views.

您不能有相对大小的空间,以便使用这些视图来代替。

You can't have relatively sized spaces so use these views instead.

如果当前的空间是发生在每一个UIView。

Where the current spaces are place a UIView in each.

然后(在code,你不能在IB做到这一点),这些设置之间的高度约束与要正确的乘数。

Then (in code as you can't do this in IB) set a height constraint between these with the correct multiplier that you want.

[NSLayoutConstraint constraintWithItem1:spacer2
                              attribute:NSLayoutAttributeHeight
                               relation:NSLayoutRelationEqual
                                  item2:spacer1
                              attribute:NSLayoutAttributeHeight
                             multiplier:0.5
                               constant:0];

然后让对方意见大棒上面和下面这些垫片观点与0间隔。

Then make the other views "stick" above and below these spacer views with 0 spacing.

然后你只需要隐藏这些意见和自动布局将完成剩下的。

Then you just have to hide these views and the auto layout will take care of the rest.

这篇关于汽车布局比例距离的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆