美文网首页
reloadSections:withRowAnimation:

reloadSections:withRowAnimation:

作者: 大风天上来 | 来源:发表于2019-12-24 11:27 被阅读0次

参考链接:https://blog.csdn.net/htl55555/article/details/82712401

在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联系人的那种展开与收缩的效果时。


由于我这边cell行高是手动设置的,就没有处理rowHeight。只对sectionHeaderHeight进行了设置。当sectionHeaderHeight值 小于或者等于 estimatedSectionHeaderHeight 时,依然有下移的问题。所以我设置estimatedSectionHeaderHeight在真实高度上+1,问题得到解决。

相关文章

网友评论

      本文标题:reloadSections:withRowAnimation:

      本文链接:https://www.haomeiwen.com/subject/uhixoctx.html