开发者

Rounded UIScrollView Performance

开发者 https://www.devze.com 2023-03-06 17:04 出处:网络
This runs great on iPhone 4 and 3GS: scrollView.layer.cornerRadius = 11; scrollView.layer.masksToBounds = YES;

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 s开发者_高级运维houldRasterize to YES and the shadowPath property), is there anything similar that can be done for CALayer's cornerRadius?


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.


Rendering of CALayers is way too slow for this use (especially on the older devices), it is not very good to use in games etc. You could switch to UIImages or cocos2d sprites, another option is to create your own layer class with OpenGL, although that one isnt quite as simple. Hope one of those options work for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号