Search code examples
iphoneperformanceiosuiscrollviewcalayer

Rounded UIScrollView Performance


This runs great on iPhone 4 and 3GS:

scrollView.layer.cornerRadius = 11;
scrollView.layer.masksToBounds = YES;

But on iPhone 3G and iPod touch 2nd gen, it makes scrolling really jerky. I know there are some tricks on how to improve performance of CALayer drop shadows for instance (setting shouldRasterize to YES and the shadowPath property), is there anything similar that can be done for CALayer's cornerRadius?


Solution

  • Is the content behind your scroll view (what’s being displayed under the rounded-off corners) a solid color or otherwise static? If so, you should be able to get way better performance by overlaying “corner” graphics—translucent at their center, and opaque (with your background color or whatever) at their edges—on top of the corners of your scroll view. The cost of compositing four 11x11 images over your content will be dramatically less than that of clipping it.