Xcode: 将对象与视图控制器边距对齐
Xcode: align objects with the View Controller margins
我开始学习 Swift 借助这个 Apple 指南:https://itunes.apple.com/it/book/app-development-with-swift/id1219117996?mt=11
现在我被困在一个小问题上,我想了解如何解决,但从指南中看不是很清楚。
我在第 398 页:“Guided Project: Personality Quiz”。
最初我必须在视图控制器的所有角落放置 4 个标签。
来自指南:
“To hold your emoji in their respective corners on all screen sizes,
you'll need to add two constraints to each label. Begin by selecting
the top-left label and clicking the Add New Constraints button. Enable
the top and leading constraints and set them both to 0 pixels,
ensuring there's no space between the edges of the label and the
margins of the view. By default, the top of a view has a 20-pixel
margin, and the left and right sides have 16 pixels of margin. So when
you enter 0 pixels, you're actually telling the label to position
itself 20 pixels from the top and 16 pixels from the left edge of the
view. Add these two constraints”
所以,按照指南,我将第一个标签放在左上角,并添加两个约束
这就是结果。标签与安全区域对齐,而不是与视图边距对齐。
看另一个项目(不是我的),我认为我需要的两个约束是这些(或类似的东西):
我将其描述为 Xcode 中的错误。您要求了 margin-relative 约束,但您没有得到它们。这不是很好!
之后您只需编辑约束即可。在最后的屏幕截图中,双击一个约束。使用弹出菜单将 Safe Area 约束更改为 Superview 约束。然后再次从菜单中选择以选中相对于保证金。那么您可能必须修复常量值。对另一个约束也这样做。
要么这样,要么一开始就不要使用约束弹出窗口。取而代之的是,通过从按钮中按住 control 并拖动来绘制约束,然后使用出现的 HUD。在 HUD 中按住 Option 以获得超级视图边距约束。
EDIT 噢,这是另一个解决方法;在形成约束之前,隐藏安全区域布局指南(取消选中此屏幕截图中的第 4 个复选框):
现在约束弹出框可以正常工作了。
我开始学习 Swift 借助这个 Apple 指南:https://itunes.apple.com/it/book/app-development-with-swift/id1219117996?mt=11
现在我被困在一个小问题上,我想了解如何解决,但从指南中看不是很清楚。
我在第 398 页:“Guided Project: Personality Quiz”。
最初我必须在视图控制器的所有角落放置 4 个标签。
来自指南:
“To hold your emoji in their respective corners on all screen sizes, you'll need to add two constraints to each label. Begin by selecting the top-left label and clicking the Add New Constraints button. Enable the top and leading constraints and set them both to 0 pixels, ensuring there's no space between the edges of the label and the margins of the view. By default, the top of a view has a 20-pixel margin, and the left and right sides have 16 pixels of margin. So when you enter 0 pixels, you're actually telling the label to position itself 20 pixels from the top and 16 pixels from the left edge of the view. Add these two constraints”
所以,按照指南,我将第一个标签放在左上角,并添加两个约束
这就是结果。标签与安全区域对齐,而不是与视图边距对齐。
看另一个项目(不是我的),我认为我需要的两个约束是这些(或类似的东西):
我将其描述为 Xcode 中的错误。您要求了 margin-relative 约束,但您没有得到它们。这不是很好!
之后您只需编辑约束即可。在最后的屏幕截图中,双击一个约束。使用弹出菜单将 Safe Area 约束更改为 Superview 约束。然后再次从菜单中选择以选中相对于保证金。那么您可能必须修复常量值。对另一个约束也这样做。
要么这样,要么一开始就不要使用约束弹出窗口。取而代之的是,通过从按钮中按住 control 并拖动来绘制约束,然后使用出现的 HUD。在 HUD 中按住 Option 以获得超级视图边距约束。
EDIT 噢,这是另一个解决方法;在形成约束之前,隐藏安全区域布局指南(取消选中此屏幕截图中的第 4 个复选框):
现在约束弹出框可以正常工作了。