1、 对项目中所有加阴影的代码进行优化
目前项目中尤其是表格单元格中使用如下加阴影代码严重影响性能(5.2.5航班查询结果页卡顿的原因)
self.cellBG.layer.shadowColor = [[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1] CGColor];
self.cellBG.layer.shadowOffset = CGSizeMake(1, 1);
self.cellBG.layer.shadowOpacity = 0.5;
self.cellBG.layer.shadowRadius = 2.0;
优化方案如下:
使用setShadowPath,优点:解决性能问题。缺点:需要获取到视图的宽和高,对于自适应的cell
shadowView.layer.shadowColor = [UIColor redColor].CGColor;
shadowView.layer.shadowOpacity = 0.5;
shadowView.layer.shadowRadius = 1.0;
shadowView.layer.shouldRasterize = YES;
shadowView.layer.rasterizationScale = [UIScreen mainScreen].scale;
CGPathRef path = [UIBezierPath bezierPathWithRect:CGRectMake(0.5, 3.5, shadowView.bounds.size.width, shadowView.bounds.size.height)].CGPath;
[shadowView.layer setShadowPath:path];
没用过,不明觉厉。
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-03 20:54:01