自动布局 - 使相关视图的高度的一半高度的SuperView [英] autolayout - make height of view relative to half superview height

查看:188
本文介绍了自动布局 - 使相关视图的高度的一半高度的SuperView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经进入自动版式最近和我卡在什么似乎像一个真正的小问题的例子。我有我想坐在屏幕的顶部,并采取了屏幕高度的一半景色。简单的自动布局之前 - 只是钉到位,并告诉它时,上海华调整为垂直展开

have been getting into autolayouts recently and I'm stuck on what seems like a really trivial problem example. I have a view that I want to sit at the top of the screen, and take up half of the screen-height. Simple before autolayout - just tack it in place and tell it to expand vertically when the superview resizes.

现在,我不能为我的生活中看到如何做到这一点。下面是我得到的,当我尝试此设置:

Now, I can't for the life of me see how to do it. Here's what I get when I try to set this up:

底部空间限制设置为等于284,当我改变iPhone4的布局,因为它保持284点空间,在屏幕的底部,这是绝对的,绝对是对我没用,并缩小视图以不再在屏幕的一半大小。而且也没有设置该约束等于任何其他视图的高度的某一部分的方式..

The bottom space constraint is set to "equals 284", which is absolute and absolutely useless to me when I change to iPhone4 layout, as it keeps 284 points space at the bottom of the screen, and shrinks the view to no longer be half the size of the screen. And there's no way of setting that constraint to equal some fraction of any other view's height..

挣扎了一会儿后,我能想到这样做的唯一的办法就是要介绍的这款视图下方另一种观点认为,同样脚的高度,让他们坐在上面和下面对方,然后将第二个(底部)视图是无形的..这似乎有点难看!

After struggling for a while, the only way I can think of doing this would be to introduce another view below this view, pin their heights equally, have them sit above and below each other and then set the second (bottom) view to be invisible.. which seems a bit ugly!

我失去了一些东西明显?..

Am I missing something obvious?..

推荐答案

这是现在可以在IB为[至少] x code 5.1.1。虽然我花了一段时间来弄清楚它实际上是超级简单:

This is now possible in IB as of [at least] Xcode 5.1.1. Although it took me sometime to figure out it is actually super simple:

首先创建一个基本的顶部对齐约束(你还需要设置下,左,右的约束,像正常)
。然后选择约束,然后导航到在属性检查:

First create a basic top alignment constraint (you will also need to setup bottom, left, and right constraints, like normal) . Then select the constraint and navigate to the Attribute inspector:

然后就可以调节倍频。如果你想要的超视图的50%拉倒 1 ,因为它是每个超级的中心对齐。这也是创建视图的其他百分比太(如超级鉴于25%)

Then you can adjust the multiplier. If you want it 50% of the super view leave it at 1, since it is aligned per the super's center. This is also a great way to create views that are other percentages too (like 25% of super view)

这篇关于自动布局 - 使相关视图的高度的一半高度的SuperView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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