Xcode 界面生成器。这些自动调整大小的蒙版设置有何不同?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9828425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode Interface Builder. How Do These Autosizing Mask Settings Differ?
提问by dugla
I am now quite comfortable using autosizing masks in IB but there are two autosizing setting that I am not clear how they are intended to differ:
我现在很习惯在 IB 中使用自动调整大小的蒙版,但是有两个自动调整大小设置我不清楚它们的区别:
设置 1
使用上下锚点自动调整大小 http://dl.dropbox.com/u/11270323/stackoverflow/autosize-mask-0.png
设置 2
仅使用上锚点自动调整大小 http://dl.dropbox.com/u/11270323/stackoverflow/autosize-mask-1.png
Some context. The UIView subclass that uses these settings is a child subview. Setting 1 is giving me the behavior I want - subview expands/contracts with its parent view - while setting 2 is slightly different in a non-obvious way.
一些上下文。使用这些设置的 UIView 子类是子子视图。设置 1 为我提供了我想要的行为 - 子视图与其父视图展开/收缩 - 而设置 2 以不明显的方式略有不同。
What is the intended layout difference between these two settings?
这两种设置之间的预期布局差异是什么?
Thanks,
Doug
谢谢,
道格
回答by BJ Homer
Setting 1:The view will resize vertically so that both the distance from the top of the superview and the distance from the bottom of the superview are preserved. Basically, the view will grow and shrink in tandem with the superview; if the superview gets taller by 30 pixels, so will this view.
设置 1:视图将垂直调整大小,以便保留与父视图顶部的距离和与父视图底部的距离。基本上,视图会与父视图同步增长和缩小;如果 superview 变高 30 像素,那么这个视图也会变高。
Setting 2:The view will resize vertically so that the distance from the top of the superview is preserved, and the proportional height of the viewis preserved. Basically, the view will grow proportionallywith the the superview; if the superview gets taller by 10%, this view will also get taller by 10%.
设置 2:视图将垂直调整大小,以便保留与父视图顶部的距离,并保留视图的比例高度。基本上,视图将与父视图成比例增长;如果超级视图变高 10%,则此视图也将变高 10%。
Note how these differ in practice. Assume the superview is 100px tall, and the subview is 60px tall, with a 20px buffer on the top and bottom. Now let's resize the superview to 150px tall.
请注意这些在实践中有何不同。假设父视图高 100 像素,子视图高 60 像素,顶部和底部有 20 像素的缓冲区。现在让我们将超级视图的大小调整为 150 像素高。
- Setting 1: The subview grows to preserve the 20px margins, becoming 110px tall.
- Setting 2: The subview grows by 50% (60px -> 90px). The top margin is still 20px, but the bottom margin is now 40px.
- 设置 1:子视图增长以保留 20 像素的边距,变成 110 像素高。
- 设置 2:子视图增长 50% (60px -> 90px)。顶部边距仍然是 20 像素,但底部边距现在是 40 像素。
In general, you usually want the behavior in Setting 1. You might use Setting 2 if you had a master/detail view split top/bottom, and you wanted both sections to grow proportionally with the superview. In that case, you would give both views flexible height, fixing the top margin of the top view and the bottom margin of the bottom view.
通常,您通常需要设置 1 中的行为。如果您有一个主/详细视图拆分顶部/底部,并且您希望两个部分与超级视图成比例地增长,则可以使用设置 2。在这种情况下,您可以为两个视图提供灵活的高度,固定顶视图的顶部边距和底部视图的底部边距。
回答by ZLN
BJ's answer is really awesome. But I think his example is incorrect.
BJ的回答真的很棒。但我认为他的例子是不正确的。
Assume the superview is 100px tall, and the subview is 60px tall, with a 20px buffer on the top and bottom. Now let's resize the superview to 150px tall.
假设父视图高 100 像素,子视图高 60 像素,顶部和底部有 20 像素的缓冲区。现在让我们将超级视图的大小调整为 150 像素高。
So for Setting 2, the top margin is undoubtedly still 20px, but the subview and the bottom margin should both grow by (150 - 20) / (100 - 20) = 62.5%. The subview height becomes 97.5px, and the bottom margin is now 32.5px.
所以对于设置 2,顶部边距无疑仍然是 20px,但是子视图和底部边距都应该增长 (150 - 20) / (100 - 20) = 62.5%。子视图高度变为 97.5px,底部边距现在为 32.5px。
In other words, the proportion of the subview height to the bottom margin should be preserved in this case.
换句话说,在这种情况下应该保留子视图高度与底部边距的比例。