Ambiguity with two inequality constraints(具有两个不等式约束的歧义)
问题描述
我希望底视图距离图像和其上方的标签至少 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).
这篇关于具有两个不等式约束的歧义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有两个不等式约束的歧义
基础教程推荐
- Android Volley - 如何动画图像加载? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
