圆角 UIScrollView 性能
这在 iPhone 4 和 3GS 上运行得很好:
scrollView.layer.cornerRadius = 11;
scrollView.layer.masksToBounds = YES;
但在 iPhone 3G 和 iPod touch 第二代上,它使滚动变得非常不稳定。我知道有一些技巧可以提高 CALayer
阴影的性能,例如(将 shouldRasterize
设置为 YES 和 shadowPath
属性),是有什么类似的事情可以为 CALayer 的cornerRadius 做吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
滚动视图后面的内容(圆角下显示的内容)是纯色还是静态?如果是这样,您应该能够通过在滚动视图的角落顶部叠加“角”图形(中心半透明,边缘不透明(带有背景颜色或其他颜色))来获得更好的性能。在内容上合成四个 11x11 图像的成本将大大低于剪切它的成本。
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.
CALayers 的渲染对于这种用途来说太慢了(尤其是在较旧的设备上),在游戏等中使用不太好。您可以切换到 UIImages 或 cocos2d sprites,另一个选择是使用 OpenGL 创建您自己的图层类,尽管那并不那么简单。希望这些选项之一适合您。
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.