有什么办法暗示自动延迟以在尊重约束时尽可能小的视图?
因此,我有一个视图,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当指定不等式的宽度/高度时,
如果T.Width是> 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
Now if t.width is < m然后它将忽略默认的低优先级,而v.width将为m
When specifying width/height with inequalities you generally need to have opposite >= and <=
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
Now if t.width is < m then it will just ignore the default low priority and v.width will be m