位置布局发生偏移(上移或下移)
if (@available(iOS 11.0, *)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//tableView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
//
tableView.contentInset = UIEdgeInsets.zero
tableView.scrollIndicatorInsets = tableView.contentInset
reloadData或reloadSections页面闪屏
//1、解决layer层闪屏问题
CATransaction.begin()
CATransaction.setCompletionBlock {
self.tableView.reloadSections(IndexSet.init(integer: sender.tag), with: .none)
}
CATransaction.commit()
//2、
UIView.setAnimationsEnabled(false)
self.tableView.reloadSections(IndexSet.init(integer: sender.tag), with: .none)
UIView.setAnimationsEnabled(true)
//3、
tableView.beginUpdates()
self.tableView.reloadSections(IndexSet.init(integer: sender.tag), with: .none)
tableView.endUpdates()
//4、
UIView.performWithoutAnimation {
self.tableView.reloadSections(IndexSet.init(integer: sender.tag), with: .none)
}
上拉加载更多数据,或刷新数据,页面位置会发生偏移,跳动,甚至是跳到了顶部
tableView.estimatedRowHeight = 44
tableView.estimatedSectionHeaderHeight = 44
tableView.estimatedSectionFooterHeight = 30
如果你没有用到预估高度,可以关闭 “=0”,我是用的约束布局,高度自适应的
无论你评论多长,高度都可以自适应。(这三行代码可以解决99%的问题)
上面提到的甚至是跳到了顶部,这个甚至是特殊业务需求的,像我这个评论页面就遇到了,去百度,去翻墙都没有找到类似案例的,当我点击收起刷新数据页面时,页面会回滚到顶部,可歌可泣!控制台打印
[Assert] Unable to determine new global row index for preReloadFirstVisibleRow (0)
我理解的是:每个分区都要有cell,没有的话他就回滚到顶部。
解决方案是:根据自己的业务需求,保证cell是0行也要返回一个高度为0的cell,保证分区至少有一个cell就可以了。