CALayer performance versus UIImageView performance

I notice that some of the things that I do with images in my application, I could do with CALayer properties (i.e. borders, shadows, gradients, etc.). Therefore, I wonder, in general, is it better to use CALayers, etc., Or just do it all in Photoshop and use UIImage (View) s for what I need? Scrolling performance was pretty slow with shadows, etc., so I'm basically trying to find any small optimizations I can.

Background information: I just scroll a bunch of images vertically. Just like a photo app. All this is starting at 3.2 years old, so I have access to things like shadow and shouldRasterize in CALayer.

+6
iphone uikit calayer uiimageview
source share
1 answer

The key thing to know about CALayer shadows is that they are displayed by default from the composite alpha channel; which can be very slow, especially when the layer rotates or changes size. You should study the shadowPath property: if you give Core Animation a simple shape, such as a rectangle ( UIBezierPath +bezierPathWithRect: with a bounds layer, you get [via its CGPath property] and you can use CGPathRef there), you will see much better performance.

shouldRasterize also definitely useful, especially with views that have many approaches that don't change often; make sure you set the rasterizationScale layer to [UIScreen mainScreen].scale , or you will get some nasty pixelation on high resolution screens like iPhone 4.

+15
source share

All Articles