如何复用CALayer
我想对自定义表格滚动视图中的每个单元格背景使用 CAGradientLayer
。如果我为每个单元格分配一个 CAGradientLayer ,滚动速度会很慢,所以我想以某种方式重用每个单元格的渐变,就像如何在一个单元格中重用 UIImage 一样UIImageView
。这样的事可能吗?
gradient = [CAGradientLayer new];
gradient.frame = innerView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
//gradient.shouldRasterize = YES;
[innerView.layer insertSublayer:gradient atIndex:0];
I want to use a CAGradientLayer
for each of the cell backgrounds in a custom table scroll view. If I allocate a CAGradientLayer
for each cell, scrolling is slow, so I would like to somehow reuse the gradient for each cell, sort of how you can reuse the UIImage
in a UIImageView
. Is such a thing possible?
gradient = [CAGradientLayer new];
gradient.frame = innerView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
//gradient.shouldRasterize = YES;
[innerView.layer insertSublayer:gradient atIndex:0];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到我可以简单地使用
UIGraphicsBeginImageContext()
将渐变 (renderInContext:
) 渲染到上下文中,并重用从中获得的图像。I realized I could simply render the gradient (
renderInContext:
) into a context usingUIGraphicsBeginImageContext()
and reuse the image obtained from it.