Adding a shadow to a cell causes scroll lag

So, I have a UIView that has a shadow:

[containerFrame.layer setShadowOffset:CGSizeMake(0, 1)];
[containerFrame.layer setShadowRadius:4.0];
[containerFrame.layer setShadowColor:[UIColor colorWithRed:34/255.f green:25/255.f blue:25/255.f alpha:1.0].CGColor];
[containerFrame.layer setShadowOpacity:0.4];

with this in place, my FPS scroll drops to 20-30. Remove the shadow and then boom, my FPS will return to 60 and the scroll will be as smooth as butter. Now the question is that I need a shadow effect around this window / container. How to achieve this without slowing down scrolling?

+5
source share
2 answers

Try setting the shadow path:

[containerFrame.layer setShadowOffset:CGSizeMake(0, 1)];
[containerFrame.layer setShadowRadius:4.0];
[containerFrame.layer setShadowColor:[UIColor colorWithRed:34/255.f green:25/255.f blue:25/255.f alpha:1.0].CGColor];
[containerFrame.layer setShadowOpacity:0.4];

// New line
[containerFrame.layer setShadowPath:[UIBezierPath bezierPathWithRect:containerFrame.bounds].CGPath];

( UITableViewCell), , , . , Core Animation, , , , . (, , .)

shadowPath.

+16

containerFrame.layer.shouldRasterize = YES; , , , . , .

+1

All Articles