1褂始、 對(duì)項(xiàng)目中所有加陰影的代碼進(jìn)行優(yōu)化
目前項(xiàng)目中尤其是表格單元格中使用如下加陰影代碼嚴(yán)重影響性能(5.2.5航班查詢結(jié)果頁(yè)卡頓的原因)
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;
優(yōu)化方案如下:
使用setShadowPath灌砖,優(yōu)點(diǎn):解決性能問題。缺點(diǎn):需要獲取到視圖的寬和高活鹰,對(duì)于自適應(yīng)的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];
沒用過分冈,不明覺厲。