在 Storyboard 中设置自动布局约束时,菜单中的同级对象不可用

Sibling object not available in menu when setting Auto Layout constraint in Storyboard

Apple 指南 "Adding Auto Layout Constraints with the Pin and Align Tools" 指出:

To create a constraint related to another item that is not the nearest neighbor, click the black down arrow in the text field and choose another nearby item from the pop-up menu.

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/pin-constraints.html

我的 Storyboard 有一个包含 UITextView 和 UIButton 的 UIView。

我会注意到这些对象在视图中是不可见的 "on the storyboard"。由于 Interface Builder 的限制,它们仅在左侧边栏中可见。所以默认情况下我不能将按钮 "to the right" 放在故事板上(如果这是导致此问题的原因)。

我需要在文本视图和按钮之间添加约束。 Text View 应该在左边,然后是 Button,中间有一个 Margin。

但是当我添加约束时,使用的两个对象是文本视图和父 UIView。不是按钮。

文本视图的"nearest neighbor"应该是按钮。

我也无法按照指南的建议select将按钮作为菜单中的第二项。只有父 UIView 可用。

为什么 Button 对象在该菜单中不可用?

我应该如何在文本视图和按钮之间添加约束?

只会显示对您选择的方向有意义的视图。因此,如果一个视图位于另一个视图之上,并且您选择了左约束或右约束,则不会显示另一个视图。如果你选择顶部约束,它应该。

另一种方法是按住 control 从文本视图拖动到场景列表中的按钮,然后从弹出窗口中选择您想要的约束 window。创建约束后,您可以根据需要对其进行编辑以更改值。