iOS 11 额外顶部 space 在 UITableView
iOS 11 Extra top space in UITableView
当我在 iOS 11 SDK 上更新我的应用程序时,TableView 开始表现得很奇怪,它添加了额外的顶部 space,但实际上那个额外的 space 是 Cell 本身,但它是未呈现,请查看 ios 11 更新之前和之后的附件图像。
谢谢!
似乎是在 iOS 11 中向 TableView 添加渐变层造成了这个问题
我不知道为什么,但是当我以编程方式添加 table 视图时,会出现 space。您只需要在 viewForHeaderInSection
中返回空视图
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
如果你想要零 space,也添加它,
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
另外,我意识到这个错误只出现在 Swift4 中。
在您的代码中设置新的 属性 contentInsetAdjustmentBehavior
,它会解决问题。
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
在 iOS 11 中添加了一个名为 contentInsetAdjustmentBehavior
的 UIScrollView 上的新 属性 来确定调整内容偏移量
This property specifies how the safe area insets are used to modify
the content area of the scroll view. The default value of this
property is automatic.
对我来说只发生在 iOS 11,我的修复:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
或
self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))
我遇到了额外的顶级 space 问题,我不得不收集一堆答案才能找到解决方案。 (5 小时检查给出的所有答案)
如果你担心,首先
Table 视图 - 模式为“组”,请将其更改为“普通”
无需对页眉或页脚部分进行任何更改,或添加与其相关的其他委托方法
然后在 InterfaceBuilder 中有您的 TableView 的 ViewController - 取消选中 Adjust Scroll View Insets - 取消选中 Extend edges: Under Top Bars
*此外,请确保您正在删除派生数据并在模拟器或 phone 中重新安装您的应用程序以反映有效完成的更改。
UI 更改有时不会反映出来,因为 IDE 也...
当我在 iOS 11 SDK 上更新我的应用程序时,TableView 开始表现得很奇怪,它添加了额外的顶部 space,但实际上那个额外的 space 是 Cell 本身,但它是未呈现,请查看 ios 11 更新之前和之后的附件图像。 谢谢!
似乎是在 iOS 11 中向 TableView 添加渐变层造成了这个问题
我不知道为什么,但是当我以编程方式添加 table 视图时,会出现 space。您只需要在 viewForHeaderInSection
中返回空视图 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
如果你想要零 space,也添加它,
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
另外,我意识到这个错误只出现在 Swift4 中。
在您的代码中设置新的 属性 contentInsetAdjustmentBehavior
,它会解决问题。
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
在 iOS 11 中添加了一个名为 contentInsetAdjustmentBehavior
的 UIScrollView 上的新 属性 来确定调整内容偏移量
This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is automatic.
对我来说只发生在 iOS 11,我的修复:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
或
self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))
我遇到了额外的顶级 space 问题,我不得不收集一堆答案才能找到解决方案。 (5 小时检查给出的所有答案)
如果你担心,首先
Table 视图 - 模式为“组”,请将其更改为“普通”
无需对页眉或页脚部分进行任何更改,或添加与其相关的其他委托方法
然后在 InterfaceBuilder 中有您的 TableView 的 ViewController - 取消选中 Adjust Scroll View Insets - 取消选中 Extend edges: Under Top Bars
*此外,请确保您正在删除派生数据并在模拟器或 phone 中重新安装您的应用程序以反映有效完成的更改。
UI 更改有时不会反映出来,因为 IDE 也...