TableView使用reloadSections:withRowAnimation: 时会向下偏移的问题

在iOS11上调用reloadSections:withRowAnimation:会出现tableview向下偏移的问题。因为tableview的load和reload,是先根据预估行高做一个轮廓的搭建,再把自定义的数据填充进去做高度的微调。所以假如不做预先的设置,默认是根据UITableViewAutomaticDimension做预估行高的(好像是44),这样的渲染导致了界面抖动,甚至到时scrollVie上移或下移。

因此需要在init方法中设置 预估行高:

self.tableView.rowHeight = 70;

 self.tableView.sectionHeaderHeight = 80;

self.tableView.estimatedRowHeight = 70;

 self.tableView.estimatedSectionHeaderHeight = 81;

注意有写博客上写的是:

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;

这样设置有时还是会有问题,所以需要设置estimatedSectionHeaderHeight的值一定要大于sectionHeaderHeight的值,特别是做类似于QQ联系人的那种展开与收缩的效果时。

你可能感兴趣的:(TableView使用reloadSections:withRowAnimation: 时会向下偏移的问题)