xcode iOS 11 UITableView 中的额外顶部空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46421673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 11 Extra top space in UITableView
提问by Lekve
When I updated my app on iOS 11 SDK , TableView started behaving Weird , It is adding extra top space , but actually that extra space is Cell itself but it is not rendered , please look through attached image before ios 11 update and after. Thank you!
当我在 iOS 11 SDK 上更新我的应用程序时,TableView 开始表现得很奇怪,它增加了额外的顶部空间,但实际上额外的空间是 Cell 本身但它没有呈现,请在 ios 11 更新之前和之后查看附加的图像。谢谢!
采纳答案by Lekve
It appears that adding gradient layer to TableView in iOS 11 creates this problem
似乎在 iOS 11 中向 TableView 添加渐变层会产生此问题
回答by BLC
Set new property contentInsetAdjustmentBehavior
in your code, it would fix the problem.
contentInsetAdjustmentBehavior
在您的代码中设置新属性,它将解决问题。
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
There is a new property on UIScrollView called contentInsetAdjustmentBehavior
added in iOS 11 to determine adjust content offset
contentInsetAdjustmentBehavior
在 iOS 11 中添加了一个名为 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.
此属性指定如何使用安全区域插入来修改滚动视图的内容区域。此属性的默认值是自动的。
回答by BLC
I don't know why but when I add table view programmatically that space occurs. All you need is returning empty view in viewForHeaderInSection
我不知道为什么,但是当我以编程方式添加表视图时,就会出现这个空间。您只需要在 viewForHeaderInSection 中返回空视图
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
If you want zero space, add it too,
如果你想要零空间,也添加它,
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
Also, I realized that bug appears only in Swift4.
另外,我意识到错误仅出现在 Swift4 中。
回答by Ben Kax
only happened on iOS 11 for me, my fix:
只发生在 iOS 11 上,我的修复:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
OR
或者
self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))
回答by pandu
I had faced the extra top space issue, I had to club a bunch of answers to reach the solution. (5 hours of checking all answers given)
我遇到了额外的顶部空间问题,我不得不收集一堆答案才能找到解决方案。(5 小时检查所有给出的答案)
first if your concerned
首先如果你关心
Table view - mode is "Group" please change it to "Plain"
表格视图 - 模式为“组”,请将其更改为“普通”
no need to do any changes to header or footer section, or add additional delegate methods related to them
无需对页眉或页脚部分进行任何更改,或添加与其相关的其他委托方法
Then in the ViewController that has your TableView in InterfaceBuilder - Uncheck Adjust Scroll View Insets - Uncheck Extend edges: Under Top Bars
然后在 InterfaceBuilder 中包含 TableView 的 ViewController - 取消选中 Adjust Scroll View Insets - 取消选中 Extend edge: Under Top Bars
*Also, make sure you are deleting derived data and re-installing your app in simulator or phone to reflect the changes done effectively.
*此外,请确保您正在删除派生数据并在模拟器或手机中重新安装您的应用程序以有效反映所做的更改。
UI changes sometimes don't reflect because of IDE also...
UI 更改有时也不会反映,因为 IDE 也...