IOS optimizes shadow code in the project
1. Optimize the shadow code in the project
Currently, the following shadow code is used in projects, especially in table cells, to seriously affect the performance (the cause of choppy flight query result page 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;
The optimization scheme is as follows:
Use setShadowPath to solve performance problems. Disadvantage: You need to obtain the width and height of the view. For the adaptive 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];
I have never used it.