惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Latest news
Latest news
L
LINUX DO - 热门话题
罗磊的独立博客
T
Tenable Blog
The Hacker News
The Hacker News
美团技术团队
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
U
Unit 42
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
爱范儿
爱范儿
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
Project Zero
Project Zero

Oragekk's Blog

OpenSpec 技术分享:用规格驱动 AI 编程 ChatGPT&Codex订阅教程 一个 waline 评论系统bug引发的思考 Jenkins 远程触发构建踩坑记 Git SSH 密钥配置 初识Rust vuepress-plugin-meting2 谷歌发布多平台应用开发神器Project IDX!PaLM 2加持 Vue常见优化手段 Vue2响应式原理解析 Dart 中的并发 Flutter 工作原理 如何利用GitHub Action提交URL到搜索引擎 提交URL到搜索引擎(百度、Bing、Google) GitHub Actions 使用介绍 素材设计 前端-Q&A 浏览器的事件循环 你不知道的 CSS 之包含块 CSS 属性计算过程 Vercel deploy忽略指定分支 评论插件 Waline 之邮件通知配置 公开API 终端究极美化iTerm2+Pure 使用Bing API提交网站URL Flutter 基础大集合 关于本站 关于本站 关于我 Markdown 展示 使用n命令管理node版本 幻灯片页 ReactNative State(状态) ReactNative开发环境配置,ES6语法介绍 ReactNative介绍 更优雅强大的终端ZSH 神经网络模型训练 YYCache优秀的缓存设计 WebViewJavascriptBridge NSError WCDB漫谈 优雅的实现TableViewCell单选 初探机器学习框架CoreML 深入理解swift中闭包的捕捉语义 ijkPlayer 集成 iOS 配置https iOS timelineLogistics iOS Cookie的配置及使用 WKWebView拦截URL WKWebView使用及自适应高度 textfield限制输入字符 评论系统从多说迁移到disqus指南 利用Runtime进行快速归档 iOS 10.3 keychain 重大更新 Cell的accessoryType属性标记单元格之后,出现的重用问题 通过UserAgent判断设备 AFNetworking A memory leak 一人一句宋词 OC 中的枚举类型 iOS - Image compression algorithm iOS程序启动原理(下) iOS程序启动原理(上) NSOperatioin Runloop Test Three ways to call Update Cocoapods 1.1.1 减小iOS-App或者静态库体积 Jekyll旧站回忆 JavaScript ES6 CommonJS,RequireJS,SeaJS 归纳笔记 Unix/Linux 扫盲笔记
TableView性能优化
Oragekk · 2016-12-26 · via Oragekk's Blog

此子必成大器

本文介绍内容主要是 tableView 的性能优化之不使用 cornerRadius 设置图片圆角

有人问我为什么 tableView 滑动不流畅,甚至闪退,其实和 cell 中的圆角头像使用了 cornerRadius 有关

优化点

  • 行高一定要缓存

  • 不要动态创建子视图

  • 所有子视图都要预先创建

  • 如果不需要显示可以设置 hidden

  • 所有的子视图都应该添加到  contentView

  • 所有的子视图都必须要指定颜色

  • 不要动态的修改 cornerRadius 之类的图层渲染相关属性

  • 使用颜色不要带透明度,此处我们可以使用模拟器中的混合模式去检测,如果如下图所示出现红色,除了 UILabel 之外,其他的我们都应该尽量去处理

  • cell 栅格化

    ``cell.layer.shouldRasterize = YES;``
    
    ``cell.layer.rasterizationScale = [UIScreen mainScreen].scale;``
    
  • 异步绘制
    // 异步绘制 layer.drawsAsynchronously = YES;

Color Blended Layers模式下
Color Blended Layers模式下

下图是使用了 CornerRadius 设置圆角之后 Color Misaligned Images 检测效果
Color Misaligned Images模式下

此处使用了一张 800*** 800 的图片设置在一个 200*200 的 ImageView 上,没有做任何特殊处理


优化步骤

  1. 新建一个 UIImage 分类

  2. 定义方法
    - (void)oa_cornerImageWithSize:(CGSize)size fillColor: (UIColor *)fillColor

    completion:(void (^)(UIImage *))completion {
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
    NSTimeInterval start = CACurrentMediaTime();
    
    	// 1. 利用绘图,建立上下文
    
    	UIGraphicsBeginImageContextWithOptions(size, YES, 0);
    	CGRect rect = CGRectMake(0, 0, size.width, size.height);
    	// 2. 设置填充颜色
    	[fillColor setFill];
    	UIRectFill(rect);
    	// 3. 利用 贝赛尔路径 `裁切 效果
    	UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
    	[path addClip];
    	// 4. 绘制图像
    	[self drawInRect:rect];
    	// 5. 取得结果
    	UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    	// 6. 关闭上下文
    	UIGraphicsEndImageContext();
    	NSLog(@"%f", CACurrentMediaTime() - start);
    	// 7. 完成回调
    	dispatch_async(dispatch_get_main_queue(), ^{
    		if (completion != nil) {
    			completion(result);
    			}
    		});
    	});
    }
    

3.控制器中代码如下

  UIImageView *iv = [[UIImageView alloc]  initWithFrame:CGRectMake(0, 0, 200, 200)];
  iv.center = self.view.center;
  [self.view addSubview:iv];
  // 设置图像
  UIImage *image = [UIImage imageNamed:@"avatar.jpg"];
  [image oa_cornerImageWithSize:iv.bounds.size fillColor:[UIColor whiteColor] completion:^(UIImage *image) {
  iv.image = image;
  }];

4.模拟器Color Blended LayersColor Misaligned Images检测结果如下图

优化之后
优化之后

5.Color Misaligned Images 如果是黄色说明图像做过拉伸处理,如果在 tableView 快速滚动中,附加操作越多,性能越差
使用如上方法不仅可以裁切圆角头像,同时解决了 800***800 设置在 200*200 的 ImageView 上会拉伸的问题
此举可以帮助 tableView 提升一部分性能