iOS: 为什么我的视图需要 x 值约束?
iOS: Why do I need an x value Constraint for my View?
我对横向 iPad 有两种看法。
一个,让我们称他为 Fred,是一个 100 像素高的矩形,与超级视图共享相同的宽度。 Fred直接进入导航栏下方
两个,我们就叫她Elize吧,是Fred里面的一个正方形,身高相同。 Elize 几乎一直在 Fred 的右边,除了 8 个像素。
这里 Fred 是绿色的,Elize Pink/Purple.
这些是我应用于 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
这还不够好,因为当我查看主故事板预览时,Elize 向左移动太多,不再位于 Fred 的右上角。
我该如何解决这个问题?
我的解决方案:给 Elize 一个 Elize.Width = Elize.Width, with constant (size of Elize; it is not polite to write this information), priority 1000, multiplier 1
的约束
解决此问题的一种方法是向 Elize 添加宽度限制。
我对横向 iPad 有两种看法。
一个,让我们称他为 Fred,是一个 100 像素高的矩形,与超级视图共享相同的宽度。 Fred直接进入导航栏下方
两个,我们就叫她Elize吧,是Fred里面的一个正方形,身高相同。 Elize 几乎一直在 Fred 的右边,除了 8 个像素。
这里 Fred 是绿色的,Elize Pink/Purple.
这些是我应用于 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
这还不够好,因为当我查看主故事板预览时,Elize 向左移动太多,不再位于 Fred 的右上角。
我该如何解决这个问题?
我的解决方案:给 Elize 一个 Elize.Width = Elize.Width, with constant (size of Elize; it is not polite to write this information), priority 1000, multiplier 1
解决此问题的一种方法是向 Elize 添加宽度限制。