使用相等高度的比例尺寸缺失约束
我希望蓝色容器视图与橙色容器视图的高度相同。我正在使用比例尺寸来这样做(所有这些都在垂直堆栈中),然后选择了所有容器,然后在其中添加了相等的高度约束。我很困惑,因为对于蓝色容器视图似乎没有比例的高度约束。我能够更改其他人的比例高度。
I would like the blue container view to be the same height as the orange container view. I am using proportional sizing to do so (all of these are within a vertical stack)I selected all of the containers then added the equal heights constraint to them. I am confused because there does not seem to be a proportional height constraint for the blue container view. I was able to change the proportional heights of the others just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
布局正是您针对高度指定的:
如果您想要“蓝色容器视图的高度与橙色容器视图相同” ,则需要设置,
您将不设置一个”比例的高度“对蓝色容器本身的约束,因为您已经告诉堆栈视图以根据这些高度约束来适合所有视图。
edit - 回答评论:“我希望蓝色本身像橙色一样较小”
如果您将其写出(或说话),您可能可以 我自己回答问题...
我想要:
。
蓝色
的
因此,让我们假设堆栈视图高度是450点,通过设置或设置顶部和底部约束 - 恰好是450点,因为它将给出这个示例的好数字。
如果我们有两种视图 - 蓝色和橙色 - 并且我们希望它们具有相同的高度,则看起来像这样:
< img src =“ https://i.sstatic.net/nf05b.png” alt =“在此处输入图像说明”>
非常简化,auto-layout说: > 1个单位,橙色等于蓝色,因此它的高度为 1个单位,总计2个高度,因此将450除以450 2并给每个视图的高度225“ ,
如果我们希望橙色高两倍,我们会约束
橙色。 :
自动layout说:“蓝色的高度为 1个单位,橙色等于蓝色x 2,因此它的高度为 2个单位。代码>并给橙色的高度
150 x 2 == 300
“ 。对于您的布局,看起来像这样:
我们现在总共有 9个高度单位(
1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 1 ),并且自动layout说:“
450/9 == 50
(每个高度单位)...” ,您可以看到它如何列出视图。The layout is exactly what you've specified for the Heights:
If you want "the blue container view to be the same height as the orange container view", you need to set
You do not set a "proportional height" constraint on the Blue Container itself, because you've already told the stack view to fit all the views based on those Height constraints.
Edit - in response to comment: "I would like the blue itself to be smaller like the orange appears"
If you write this out (or speak it), you can probably answer the question yourself...
I want :
So...
Maybe this will help you understand...
We don't assign a Height to the Blue view, because we are using the Height of the stack view to arrange its subviews.
So, let's assume the stack view Height is 450-points, either by setting it or by setting Top and Bottom constraints - and it just happens to be 450 because it will give this example nice numbers.
If we have Two views - Blue and Orange - and we want them the same Height, it looks like this:
Very simplified, auto-layout says: "Blue has a Height of 1 unit, Orange is equal to Blue, so it also has a Height of 1 unit. 1 + 1 == 2, for a total of 2 Height units, so divide 450 by 2 and give each view a height of 225"
If we want Orange to be twice as tall as Blue, we constrain
Orange.Height = Blue.Height with Multiplier: 2
and we get this:Auto-layout says: "Blue has a Height of 1 unit, Orange is equal to Blue x 2, so it has a Height of 2 units. 1 + 2 == 3 total Height units...
450 / 3 == 150
, so give Blue a Height of1 x 150 == 150
and give Orange a Height of150 x 2 == 300
".For your layout, it looks like this:
We now have a total of 9 Height units (
1 + 1 + 2 + 2 + 2 + 1
), and auto-layout says: "450 / 9 == 50
(per Height unit) ..." and you can see how it lays out the views.