CALayer, shadows, and performance.

On iPad, we get shadows on CALayers..

So, you can do this:

aView.layer.shadowColor = [[UIColor darkGrayColor] CGColor];
aView.layer.shadowOffset = CGSizeMake(3., 3.);
aView.layer.shadowOpacity = 0.8;
aView.layer.shadowRadius = 5.;

However, you’ll notice that with a few of those onscreen and suddenly your splendidly fast iPad starts acting like it’s computing through a puddle of molasses. The cause turns out to be those darn shadows, they’re re-composited every time the layer moves. The fix is easy as microwavable popcorn:

aView.layer.shouldRasterize = YES;

Welcome back superfast iPad! :)

Friday, April 9, 2010