iOS Stack

UITableView的性能优化

2017-08-14  本文已影响8人  de7e01056dd4
屏幕显示图像的原理

计算机系统中CPU 计算好显示内容提交到GPU,GPU渲染完成后将渲染结果放入帧缓冲区中,随后视频控制器会按照VSync信号逐行读取帧缓冲区的数据,经过可能的数模转换传递给显示器显示

离屏渲染的触发方式

设置以下属性时都会触发离屏绘制:
shouldRasterize(光栅化)
masks(遮罩)
shadows(阴影)
edge antialiasing(抗锯齿)
group opacity(不透明)
复杂形状设置圆角等
渐变

解决tableView滑动的时候卡顿的问题:

UITableViewCell高度计算优化(FDTemplateLayoutCell)
self.tableView.rowHeight = 88;

对于定高需求的表格,强烈建议使用这种(而非下面的)方式保证不必要的高度计算和调用

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    // return xxx
}

需要注意的是,实现了这个方法后,rowHeight 的设置将无效。所以,这个方法适用于具有多种 cell 高度的 UITableView

UITableView 优化历程

测试环境 iphone6s iOS10.2

  1. 首先是发现卡顿
 _tableView.estimatedRowHeight = 80;
 _tableView.rowHeight = UITableViewAutomaticDimension;
[_tableView registerNib:[UINib nibWithNibName:@"TagCell" bundle:nil] forCellReuseIdentifier:CellID];
cell图片切圆角
    [_iconImage yy_setImageWithURL:url placeholder:nil options:YYWebImageOptionShowNetworkActivity  | YYWebImageOptionAllowBackgroundTask   completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
        UIImage * rediusImage = [image imageByRoundCornerRadius:image.size.height/2];
        _iconImage.image = rediusImage;
    }];
屏幕快照 2017-09-08 上午10.11.08.png

一个单样式的TableView,FPS基本都低于55

参考链接:

UIKit性能调优
iOS 保持界面流畅的技巧

上一篇 下一篇

猜你喜欢

热点阅读