iOS 11 UITableView中的额外顶部空间

Lek*_*kve 3 xcode tableview ios swift ios11

当我在iOS 11 SDK上更新我的应用程序时,TableView开始表现奇怪,它增加了额外的顶部空间,但实际上额外的空间是Cell本身但它没有渲染,请在ios 11更新之前和之后查看附加图像.谢谢!

这是在ios 11更新之后

在ios 11之前

BLC*_*BLC 24

contentInsetAdjustmentBehavior在代码中设置新属性,它将解决问题.

if #available(iOS 11.0, *) {
    collectionView.contentInsetAdjustmentBehavior = .never
}
Run Code Online (Sandbox Code Playgroud)

UIScrollView上有一个名为contentInsetAdjustmentBehavioriOS 11中添加的新属性,用于确定调整内容偏移量

此属性指定如何使用安全区域insets来修改滚动视图的内容区域.此属性的默认值是自动的.


小智 6

我不知道为什么,但是当我以编程方式添加表视图时,会出现空间.您只需要在viewForHeaderInSection中返回空视图

 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return UIView()
}
Run Code Online (Sandbox Code Playgroud)

如果你想要零空间,也可以添加它,

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.01
}
Run Code Online (Sandbox Code Playgroud)

此外,我意识到bug只出现在Swift4中.