使用相等高度的比例尺寸缺失约束

发布于 2025-01-26 23:20:38 字数 441 浏览 5 评论 0原文

我希望蓝色容器视图与橙色容器视图的高度相同。我正在使用比例尺寸来这样做(所有这些都在垂直堆栈中),然后选择了所有容器,然后在其中添加了相等的高度约束。我很困惑,因为对于蓝色容器视图似乎没有比例的高度约束。我能够更改其他人的比例高度。

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.

enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2025-02-02 23:20:38

布局正是您针对高度指定的:

Orange: 0.5 * Blue (1/2 Blue Height)
Green:  == Blue
Yellow: == Blue
Purple: == Blue
Grey:   0.5 * Blue (1/2 Blue Height)

如果您想要“蓝色容器视图的高度与橙色容器视图相同” ,则需要设置,

Orange: == Blue
Green:  == Blue
Yellow: == Blue
Purple: == Blue
Grey:   0.5 * Blue (1/2 Blue Height)

您将不设置一个”比例的高度“对蓝色容器本身的约束,因为您已经告诉堆栈视图以根据这些高度约束来适合所有视图。


edit - 回答评论:“我希望蓝色本身像橙色一样较小”

如果您将其写出(或说话),您可能可以 我自己回答问题...

我想要:

  • 橙色。高度等于蓝色
  • 。高高的灰色。高度等于蓝色
  • 。高高的绿色。高高的高度是蓝色的两倍。Heightheight
  • height height两倍,是蓝色的两倍
  • 。 高度

Orange: == Blue
Grey:   == Blue
Green:  == Blue * 2.0
Yellow: == Blue * 2.0
Purple: == Blue * 2.0

蓝色

因此,让我们假设堆栈视图高度是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:

Orange: 0.5 * Blue (1/2 Blue Height)
Green:  == Blue
Yellow: == Blue
Purple: == Blue
Grey:   0.5 * Blue (1/2 Blue Height)

If you want "the blue container view to be the same height as the orange container view", you need to set

Orange: == Blue
Green:  == Blue
Yellow: == Blue
Purple: == Blue
Grey:   0.5 * Blue (1/2 Blue Height)

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 :

  • orange.height equal to blue.height
  • grey.height equal to blue.height
  • green.height twice as tall as blue.height
  • yellow.height twice as tall as blue.height
  • purple.height twice as tall as blue.height

So...

Orange: == Blue
Grey:   == Blue
Green:  == Blue * 2.0
Yellow: == Blue * 2.0
Purple: == Blue * 2.0

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:

enter image description here

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:

enter image description here

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 of 1 x 150 == 150 and give Orange a Height of 150 x 2 == 300".

For your layout, it looks like this:

enter image description here

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文