美文网首页
UIImageView简单的性能优化

UIImageView简单的性能优化

作者: farmerly | 来源:发表于2018-08-17 12:41 被阅读8次

看代码吧~

  • 可以设置上下左右四个方向任意圆角
  • 更具图片大小判断圆角大小
分类: UIImageView+Extension.h
/*
 设置圆角优化图片性能
 UIRectCornerTopLeft     = 1 << 0,
 UIRectCornerTopRight    = 1 << 1,
 UIRectCornerBottomLeft  = 1 << 2,
 UIRectCornerBottomRight = 1 << 3,
 UIRectCornerAllCorners  = ~0UL
 radiusSize     设置圆角大小(按照图片大小计算)
 cornerPosition 设置圆角位置
 */
- (void)imageOptimizePerformance:(CGSize)radiusSize 
  cornerPosition:(UIRectCorner)cornerPosition;
分类: UIImageView+Extension.m
 - (void)imageOptimizePerformance:(CGSize)radiusSize       
    cornerPosition:(UIRectCorner)cornerPosition{

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:cornerPosition cornerRadii:radiusSize];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
//设置大小
maskLayer.frame = self.bounds;
//设置图形样子
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
一次性要裁剪四个脚,混合图层,图片多了会导致异常卡顿
优化前.png

优化前

UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 60, 100, 100)];
imageView.layer.cornerRadius = 20;
imageView.layer.masksToBounds = YES;
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://img.zcool.cn/community/0117e2571b8b246ac72538120dd8a4.jpg"]];
[self.view addSubview:imageView];

优化后


优化后.png
 UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 60, 100, 100)];、
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://img.zcool.cn/community/0117e2571b8b246ac72538120dd8a4.jpg"]];    
 [imageView imageOptimizePerformance:CGSizeMake(20, 20) cornerPosition:UIRectCornerTopLeft|UIRectCornerTopRight];
[self.view addSubview:imageView];

如果需要更好的性能,加上蒙版加上绘制,但是以这种方式已经可以达到微信朋友圈的性能要求了,当然你如果想要微博一样的性能,就需要对cell的加载进行大量的优化了。

相关文章

  • UIImageView简单的性能优化

    看代码吧~ 可以设置上下左右四个方向任意圆角 更具图片大小判断圆角大小 分类: UIImageView+Exte...

  • UIImageView UIView圆角与性能之间的研究与优化

    UIImageView UIView圆角与性能之间的研究与优化 设想: 场景: 实际: UIImageView 结...

  • UIImageView的性能优化

    UIImageView是我们经常使用的UI控件,平时感觉不到有什么好优化的,其实不然。最近研究这个控件,其实可以从...

  • IOS基础知识-离屏渲染原理篇

    优化方案 官方对离屏渲染产生性能问题也进行了优化: iOS 9.0 之前UIimageView跟UIButton设...

  • UIImageView优化

    对于UIImageView的优化,无非就是对UIImageView加载图片进行优化,作者本人是看过YYKit、As...

  • Web前端性能优化进阶——完结篇

    前言 在之前的文章 如何优化网站性能,提高页面加载速度 中,我们简单介绍了网站性能优化的重要性以及几种网站性能优化...

  • React 性能优化

    React 性能优化 简单的 todo-list-demo 讲 React 性能优化不能光靠嘴说,得有一个 dem...

  • React性能优化方案

    React 性能优化 简单的 todo-list-demo 讲 React 性能优化不能光靠嘴说,得有一个 dem...

  • Awesome Extra

    性能优化 性能优化模式 常见性能优化策略的总结 Spark 性能优化指南——基础篇 Spark 性能优化指南——高...

  • Android性能优化 - 消除卡顿

    性能优化系列阅读 Android性能优化 性能优化 - 消除卡顿 性能优化 - 内存优化 性能分析工具 - Tra...

网友评论

      本文标题:UIImageView简单的性能优化

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