保持界面流畅技巧

2018-12-21  本文已影响14人  liboxiang

https://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/
https://objccn.io/issue-3-1/

http://www.imlifengfeng.com/blog/?p=593
https://robots.thoughtbot.com/designing-for-ios-graphics-performance

tumblr_mdyk43n5jr1qatp4h.png
Snip20180524_2.png

离屏渲染

CPU的offscreen-render
GPU的offscreen-render

与硬件(GPU)加速绘图相比,上述CPU处理的任何类型的绘图都很慢,但它们不一定会减慢您的应用程序速度,因为它们不需要每帧都发生。例如,第一次在视图上绘制投影时速度很慢,但在绘制之后它会被缓存,并且只有在视图更改大小或形状时才会重绘。

为了获得良好的性能,诀窍是避免使用软件绘制来改变每一帧的视图。例如,如果您需要动画矢量形状,使用CAShapeLayer或OpenGL比使用drawRect和Core Graphics获得更好的性能。但是如果你画一次形状然后不需要改变它,它就没有太大的区别。

三种观点

个人认为具体情况具体处理,当遇到性能瓶颈的时候需要看是CPU还是GPU造成的性能瓶颈,并进行相应优化

具体的优化方法

使用CAShapeLayer和UIBezierPath设置圆角

UIImageView *imageView = [[UIImageView >alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; 
imageView.image = [UIImage imageNamed:@"myImg"]; 
UIBezierPath *maskPath = [UIBezierPath >bezierPathWithRoundedRect:imageView.bounds >byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init]; 
//设置大小 
maskLayer.frame = imageView.bounds; 
//设置图形样子 
maskLayer.path = maskPath.CGPath;
imageView.layer.mask = maskLayer; 
[self.view addSubview:imageView];

view.layer.backgroundColor = [UIColor blueColor].CGColor;
view.layer.cornerRadius = 10;
imageView.layer.shadowColor = [UIColor grayColor].CGColor;
imageView.layer.shadowOpacity = 1.0;
imageView.layer.shadowRadius = 2.0;
UIBezierPath *path = [UIBezierPath bezierPathWithRect:imageView.frame];
imageView.layer.shadowPath = path.CGPath;

FlexBox布局

https://juejin.im/post/5a33a6926fb9a045104a8d3c

相关SDK

AsyncDisplayKit

https://www.jianshu.com/p/5c8fb81cf8ab

上一篇下一篇

猜你喜欢

热点阅读