有什么办法暗示自动延迟以在尊重约束时尽可能小的视图?

发布于 2025-02-12 04:15:55 字数 553 浏览 0 评论 0原文

因此,我有一个视图,v,我想以下面的方式约束:

  • v的大小最小:m
  • v v v应水平扩展以适合内部包含的文本视图,t
  • v应集中在Supperiew中,s
  • v v v v。 应尽可能小。

因此,我试图通过以下约束来实现这一目标:

v.width >= m
v.width >= t.width
v.centerX == s.centerX

借助这些约束,问题在于,视图增长以填补整个监督。

如果我删除约束v.width> = m,则视图缩放到包裹t与可能性一样紧密。

无论如何,是否有暗示自动布局,它应该尝试使v尽可能小时,而不会破坏约束?

So I have a view, v, which I want to constrain in the following way:

  • v has a minimum size: m
  • v should scale horizontally to fit the text view contained inside, t
  • v should be centered inside the superview, s
  • v should be as small as possible.

So I have tried to achieve this with the following constraints:

v.width >= m
v.width >= t.width
v.centerX == s.centerX

With these constraints, the problem is that the view grows to fill the entirety of the superview.

If I remove the constraint v.width >= m then the view scales to wrap t as closely as possilble.

Is there anyway to hint to auto layout that it should try to make v as small as possible without breaking the constraints?

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

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

发布评论

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

评论(1

递刀给你 2025-02-19 04:15:55

当指定不等式的宽度/高度时,

v.width >= m
v.width <= t.width

如果T.Width是&gt; gt; M,然后有一个答案,可以满足两个方程式的满足。

但是T.Width可能是Lt; M,所以您需要不同的优先级:
If you have two >= priorities then there's ambiguity about how much greater the value should be to satisfy all the equations

v.width >= m, priority .defaultHigh
v.width <= t.width, priority .defaultLow

Now if t.width is < m然后它将忽略默认的低优先级,而v.width将为m

When specifying width/height with inequalities you generally need to have opposite >= and <=

v.width >= m
v.width <= t.width

This way if t.width is > m, then there's an answer for how wide satisfies both equations.

But t.width could be < m, so you need different priorities:
If you have two >= priorities then there's ambiguity about how much greater the value should be to satisfy all the equations

v.width >= m, priority .defaultHigh
v.width <= t.width, priority .defaultLow

Now if t.width is < m then it will just ignore the default low priority and v.width will be m

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