列表界面的卡顿优化,除了缓存计算高度,
还可以开个线程,异步计算高度并缓存,
再回到主线程,刷新界面
还有图片解码消耗性能, …
-
使用纯代码,取代 xib ( xib, 一般会被解析成代码 )
-
减少 UI 显示层级, ( zIndex 方向上 )
-
合并用来显示的控件, ( UI 控件,数量上 )
例如:
一个 Label 的富文本 = 多个 Lable 的纯文本
- 避免离屏渲染
避免使用到,离屏渲染缓冲区
( 苹果已经,优化得很好了 )
本文重点介绍,多线程大法
对于复杂的列表显示,
一般都是,滚动的时候,更卡顿
- A 修改前,
A 特点 0,没有缓存高度
cell 的高度,触发直接计算
先渲染,再取高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
TimeLineCell *cell = [[TimeLineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell configureTimeLineCell:timeLineModel];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell setNeedsLayout];
[cell layoutIfNeeded];
CGFloat rowHeight = 0;
for (UIView *bottomView in cell.contentView.subviews) {
if (rowHeight < CGRectGetMaxY(bottomView.frame)) {
rowHeight = CGRectGetMaxY(bottomView.frame);
}
}
return rowHeight;
}
A 特点 1,cell 中控件渲染的同时,在计算
一个 cell, 下面的图片展示相关
五种布局:
没有图片
单张
二三张
4 张
5 张及以上
for (UIButton *btn in self.contentImageBtns) {
[btn removeFromSuperview];
}
[self.contentImageBtns removeAllObjects];
if (timeLineModel.contentImages.cou