问题描述
当我将子视图添加到根 ViewController 的视图中,并且自动布局设置leadingSpace、trailingSpace、topSpace 和 bottomSpace 为零时,左右两侧会出现一些额外的空间(所以如果我打印 subview 的框架,它的原点将为 16并且 32 的尺寸小于应有的尺寸).所以实际上我们得到前导和尾随空格不是零......
When I add subview to root ViewController's view, and with auto layout setup leadingSpace,trailingSpace,topSpace and bottomSpace to zero, there are appear some extra spaces on left and right sides (so if I print subview's frame its origin will be 16 and size less on 32 than should be). So actually we get that leading and trailing spaces are not zeros...
正如您在图片前导空格上看到的 - 零,但 origin.x = 16
As you can see on picture leading space - zero, but origin.x = 16
早些时候我没有努力使用自动布局,所以我的问题是:是新 Xcode 的 bug 还是功能?
Earlier I wasn't working hard with auto layout, so my question is: Is it a bug of new Xcode or a feature?
附:所有框架和约束都已更新.
P.S. All frames and constraints updated.
推荐答案
iOS 8 增加了 内容边距" 到 UIView
.来自 WWDC 2014 的 What's New in Cocoa Touch"视频讨论了内容边距(在标题下自适应边距")从大约 12 分 30 秒开始.
iOS 8 adds the concept of "content margins" to UIView
. The "What's New in Cocoa Touch" video from WWDC 2014 discusses content margins (under the title "Adaptive Margins") starting at about 12m30s.
默认边距为每边 8 磅.布局约束的每一端都可以相对于视图的边缘而不是视图的真实边缘(使用 File > Open Quickly 转到 NSLayoutAttribute
的定义以查看可能性).
The default margins are 8 points on each side. Each end of a layout constraint can be relative to a view's margin instead of to the view's true edge (use File > Open Quickly to go to the definition of NSLayoutAttribute
to see the possibilities).
您的约束是相对于边距".当您使用添加新约束"弹出框创建约束时,您可以选择它是否与边距相关:
Your constraint is "relative to margin". When you create the constraint with the "Add New Constraints" popover, you can choose whether it's margin-relative or not:
它总是默认为margin-relative;如果您不希望它们与边距相关,则每次添加约束时都必须关闭该复选框.
It always defaults to margin-relative; you have to turn the checkbox off every time you add constraints if you don't want them to be margin-relative.
您无法在屏幕截图的快速编辑弹出窗口中更改约束是否与边距相关.相反,双击约束以调出其完整的属性检查器.在那里,您可以使用弹出菜单为约束的每一端选择是否与边距相关:
You can't change whether a constraint is margin-relative in the quick-edit popover of your screen shot. Instead, double-click the constraint to bring up its full Attributes inspector. There, you can use the popup menus to select, for each end of the constraint, whether it's margin-relative or not:
这篇关于Xcode 6 beta 7:故事板在左右两侧增加了额外的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!