XCode 6.3向tableviewcell添加边距 [英] XCode 6.3 adding margins to tableviewcell

查看:331
本文介绍了XCode 6.3向tableviewcell添加边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XCode 6.3 / Swift 1.2是否为UITableViewCell的contentView添加了额外的边距?在更新之前,我有一个自定义的UIView,它在我的单元格中一直延伸到整个屏幕。示例:

Did XCode 6.3 / Swift 1.2 add additional margins to a UITableViewCell's contentView? Prior to updating, I had a custom UIView that extended all the way across the screen in my cells. Example:

现在,单元格中的所有内容似乎都有额外的边距,我不知道它们来自哪里。

Now, everything in the cell seems to have additional margins that I have no idea where they came from.

请注意,这些视图的宽度不是在代码中以任何方式改变,左右限制如下:

Note that these view's widths are not altered in any way in code and the right and left are constrained as below:

另请注意,我使用的是 tableView.separatorStyle = .None 。我添加这个事实是因为出于某种原因我的 tableView 中有一个具有默认分隔符,它似乎没有添加这些额外的边距。

Also note that I am using tableView.separatorStyle = .None. I add this fact because for some reason in one of my tableViews that has the default separator, it doesn't appear to add these additional margins.

有没有人知道他们是否在XCode 6.3中做了一些奇怪的改变?更新后会直接发生此行为。

Does anyone know if they did some weird change in XCode 6.3? This behavior occurred directly after updating.

编辑:

推荐答案

仔细查看尺寸检查器的此屏幕截图,了解主要约束:

Look carefully at this screen shot of the Size inspector for a leading constraint:

查看如何检查相对保证金?那是你的问题。如果边距发生变化,则左边缘会发生变化。 取消选中该菜单项,然后将常量更改为零。对于尾随约束也是如此,你的问题将会结束。

See how "Relative to margin" is checked? That's your problem. If the margin changes, your left edge changes. Uncheck that menu item and then change the Constant to zero. Do that for the trailing constraint too, and your problems will be over.

现在让我们解决更深层次的问题:改变了什么?你是绝对正确的,有些事情。我相信他们修复了一个错误,你陷入了修复。记录显示单元格的 preservesSuperviewLayoutMargins true ,并且表格的边距是 0,16 ,0,16 。即使在iOS 8.2上也是如此,因此iOS 8.2 上的有效边距应为16.但它们是8,好像 preservesSuperviewLayoutMargins 。但是在iOS 8.3中,正确地遵循了这个设置 - 结果你已经观察到了。

Now let's address the deeper issue: what changed? You are absolutely right, something did. I believe they fixed a bug, and you got caught in the fix. Logging shows me that the cell's preservesSuperviewLayoutMargins is true and that the table's margins are 0,16,0,16. This is true even on iOS 8.2, so the effective margins on iOS 8.2 should have been 16. But they were 8, as if preservesSuperviewLayoutMargins were false. But in iOS 8.3, this setting is obeyed properly — with the result that you have observed.

因此,另一种解决问题的方法会一直保留你的约束,但是要在 preservesSuperviewLayoutMargins 设置为 false >的cellForRowAtIndexPath:。这同样适用于在两个系统中使结果相同。

Thus, another way to fix the problem would have been to leave your constraints as they are, but to set each cell's preservesSuperviewLayoutMargins to false in cellForRowAtIndexPath:. This works equally well to make the outcome identical in both systems.

编辑好消息:看起来这个更改在iOS 9中被还原。因此,在不改变的情况下,iOS 9中的单元格与iOS 8.2及之前的单元格相同。

EDIT Good news: it looks like this change is reverted in iOS 9. Thus, without change, your cells would look the same in iOS 9 as they did in iOS 8.2 and before.

这篇关于XCode 6.3向tableviewcell添加边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆