目录

UITableview调用reload方法时抖动问题

目录

由于UITableview在iOS11的时候加入了Self-Sizing新特性,而且cell、header、footer是默认开启的,导致estimated的高度值变成了UITableViewAutomaticDimension(之前是0)。

如果不曾设置过estimateRowHeight属性的话,reload的时候可能会有一些奇怪的上下抖动,UITableview的位置也有可能不再停留在原来的位置。

解决方案就是给这些预估值赋值为0来禁用:

1
2
3
4
5
if (@available(iOS 11.0, *)) {
    UITableView.appearance.estimatedRowHeight = 0;
    UITableView.appearance.estimatedSectionFooterHeight = 0;
    UITableView.appearance.estimatedSectionHeaderHeight = 0;
}