具有两个不等式约束的歧义 [英] Ambiguity with two inequality constraints

查看:13
本文介绍了具有两个不等式约束的歧义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望底视图距离图像其上方的标签至少 20 距离.标签是多行的,因此它可以比图像视图更高或更短,具体取决于有多少文本.当我添加两个到最近邻居的距离 >= 20"的约束(如屏幕截图所示)时,Xcode 告诉我约束不明确.

I want to have the bottom view be at least 20 away from both the image and the label above it. The label is multiline, so it can be taller or shorter than the image view, depending on how much text there is. When I add two "distance to nearest neighbour >= 20" constraints like shown in the screenshot, Xcode tells me constraints are ambiguous.

我该如何解决?

推荐答案

如果我理解您的要求,我认为您可以这样做:

I think you can do it like this, if I understand your requirements:

图像视图具有固定的宽度和高度,左侧和顶部的约束,以及底部视图的约束 =20优先级为 700.这很关键——这将设置该底部视图的 y 位置(其具有固定的高度和两侧的约束),但如果另一个具有更高优先级的约束使其移动,它将允许它移动得更低.具有更高优先级的约束是对标签的约束——它 >=20,优先级为 1000(标签还对图像视图的顶部、右侧和后沿有约束).

The image view has a fixed width and height, and constraints to the left side and top, as well as a constraint to the bottom view of =20 with a priority of 700. That's crucial -- that will set the y position of that bottom view (which has fixed height and constraints to the two sides), but will allow it to move lower if another constraint with higher priority makes it. That constraint with higher priority is the constraint to the label -- it's >=20 with priority of 1000 (the label also has constraints to the top, right side, and trailing edge of the image view).

这篇关于具有两个不等式约束的歧义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆