他们是否在iOS 11中为UITableVIew添加了更多填充?

Phi*_*lip 8 iphone xcode uitableview ios ios11

是仅仅是我还是他们UITableView在iOS 11中为分组页眉和页脚添加了更多填充?

我编译我的应用程序以运行iOS 11并注意到额外的填充.我有点解决了它,通过设置contentInset.top负值来检查操作系统是否是iOS 11,但这是一个丑陋的解决方法.

有没有其他更好的方法可以清除分组表视图的额外填充,以便在所有支持的iOS上实现相同的结果?对这种愚蠢的事情进行多次检查有点臭.

比较截图:

iOS 10 vs iOS 11 UITableView比较

正如您所看到的,在iOS 11上,各部分之间有额外的间距(是的,这些是部分!).

Ras*_*hid 12

这是UIScrollView的新contentInsetAdjustmentBehavior参数,您可以将其设置为.never以防止额外填充

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

或在Size Inspector下的storyboard中

在此输入图像描述


小智 2

您只需要设置表格视图的页眉和页脚视图。

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
Run Code Online (Sandbox Code Playgroud)