<bdo id='J17x1'></bdo><ul id='J17x1'></ul>

    <i id='J17x1'><tr id='J17x1'><dt id='J17x1'><q id='J17x1'><span id='J17x1'><b id='J17x1'><form id='J17x1'><ins id='J17x1'></ins><ul id='J17x1'></ul><sub id='J17x1'></sub></form><legend id='J17x1'></legend><bdo id='J17x1'><pre id='J17x1'><center id='J17x1'></center></pre></bdo></b><th id='J17x1'></th></span></q></dt></tr></i><div id='J17x1'><tfoot id='J17x1'></tfoot><dl id='J17x1'><fieldset id='J17x1'></fieldset></dl></div>
    <legend id='J17x1'><style id='J17x1'><dir id='J17x1'><q id='J17x1'></q></dir></style></legend>
  • <small id='J17x1'></small><noframes id='J17x1'>

    <tfoot id='J17x1'></tfoot>

        自动布局 - 使视图高度相对于超级视图的一半高度

        时间:2023-09-11
        • <bdo id='wgDo5'></bdo><ul id='wgDo5'></ul>

        • <small id='wgDo5'></small><noframes id='wgDo5'>

            <tbody id='wgDo5'></tbody>

        • <tfoot id='wgDo5'></tfoot>
          <legend id='wgDo5'><style id='wgDo5'><dir id='wgDo5'><q id='wgDo5'></q></dir></style></legend>

              • <i id='wgDo5'><tr id='wgDo5'><dt id='wgDo5'><q id='wgDo5'><span id='wgDo5'><b id='wgDo5'><form id='wgDo5'><ins id='wgDo5'></ins><ul id='wgDo5'></ul><sub id='wgDo5'></sub></form><legend id='wgDo5'></legend><bdo id='wgDo5'><pre id='wgDo5'><center id='wgDo5'></center></pre></bdo></b><th id='wgDo5'></th></span></q></dt></tr></i><div id='wgDo5'><tfoot id='wgDo5'></tfoot><dl id='wgDo5'><fieldset id='wgDo5'></fieldset></dl></div>
                  本文介绍了自动布局 - 使视图高度相对于超级视图的一半高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  最近一直在使用自动布局,但我被困在一个看似非常微不足道的问题示例上.我有一个视图,我想坐在屏幕的顶部,并占据屏幕高度的一半.在自动布局之前很简单 - 只需将其固定到位并告诉它在超级视图调整大小时垂直扩展.

                  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 中是可能的 [至少] Xcode 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:

                  首先创建一个基本的顶部对齐约束(您还需要设置底部、左侧和右侧约束,就像正常一样).然后选择约束并导航到 Attribute 检查器:

                  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)

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

                  上一篇:UIStackView 分布填充均等 下一篇:具有自动布局左边距的 UITableViewCell 在 iPhone 和 iPad 上不同

                  相关文章

                  • <bdo id='QMVVj'></bdo><ul id='QMVVj'></ul>
                  <legend id='QMVVj'><style id='QMVVj'><dir id='QMVVj'><q id='QMVVj'></q></dir></style></legend>

                • <small id='QMVVj'></small><noframes id='QMVVj'>

                      <tfoot id='QMVVj'></tfoot>
                      <i id='QMVVj'><tr id='QMVVj'><dt id='QMVVj'><q id='QMVVj'><span id='QMVVj'><b id='QMVVj'><form id='QMVVj'><ins id='QMVVj'></ins><ul id='QMVVj'></ul><sub id='QMVVj'></sub></form><legend id='QMVVj'></legend><bdo id='QMVVj'><pre id='QMVVj'><center id='QMVVj'></center></pre></bdo></b><th id='QMVVj'></th></span></q></dt></tr></i><div id='QMVVj'><tfoot id='QMVVj'></tfoot><dl id='QMVVj'><fieldset id='QMVVj'></fieldset></dl></div>