iOS:为什么我的 View 需要 x 值约束?

标签 ios autolayout constraints

我在 iPad 上有两个横向 View 。

一个,让我们称他为 Fred,是一个 100 像素高的矩形,与父 View 共享相同的宽度。 Fred 直接进入导航栏下方。

两个,我们称她为 Elize,是 Fred 内部的一个正方形,高度相同。除了 8 个像素外,Elize 几乎一直位于 Fred 的右侧。

enter image description here

这里 Fred 是绿色的,Elize 是粉色/紫色的。

这些是我对 Elize 施加的约束:

Fred.Trailing = Elize.Trailing, with constant 8, priority 1000, and multiplier 1
Elize.Top = Fred.Top, with constant 0, priority 1000, and multiplier 1
Elize.Height = Fred.Height, with constant 0, priority 1000, and multiplier 1

即使有这些限制,Xcode 也会在文档大纲中给我一个红色警告标志,表示 Elize 需要 x 位置的限制。当我允许 Xcode 为我选择此约束时,它会选择:

Elize.Leading = Fred.Leading, with constant 684, priority 1000, multiplier 1

这还不够好,因为当我查看主 Storyboard预览时,Elize 向左移动太多,不再位于 Fred 的右角。

我该如何解决这个问题?

最佳答案

解决此问题的一种方法是向 Elize 添加宽度约束。

关于iOS:为什么我的 View 需要 x 值约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31866251/

相关文章:

ios - NSLayoutConstraint 抛出异常 "is not a key in the views dictionary"

c++ - 为什么我的模板特化需要匹配原始约束?

ios - 自动布局旋转固定位置

iOS 混淆日志 : Unable to simultaneously satisfy constraints

algorithm - Dancing Links 可以应用于此 CSP 吗?

ios - 如何在 iOS App Store 上部署 Vue Native 应用程序?

javascript - 获取 WKWebView 的内容高度不正确

iphone - 锁定屏幕上的 "Slide to snooze"

iPhone:哪个 Controller 应该处理 CRUD 逻辑?

ios - 在 UIContainerView swift ios 中调整 subview Controller 的大小