设置“不透明度”绘制之前的 CGLayer ?

发布于 2024-08-16 21:12:02 字数 235 浏览 5 评论 0原文

我有 UIView 子类 - 实际上是一个拼图 - 有 2 个不同的 CGLayer 在 initWithFrame 初始化。

在drawRect中,我必须混合这两层,并且最上面应该有可变alpha,具体取决于游戏逻辑。

执行此操作的最佳(性能最优化)方法是什么?是否有任何 CGLayer 或 CGContext 函数可以在绘制之前设置一些 alpha?

I have UIView subclass - actually a puzzle piece - with 2 different CGLayer initialized at initWithFrame.

In drawRect I have to blend this two layer, and the uppermost should have variable alpha depending on game-logic.

What is the best (most performance optimized) way to do this? Is there any CGLayer, or CGContext function that sets some alpha before drawing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我要还你自由 2024-08-23 21:12:02

设置图层的-opacity。请记住,图层的 -opaque 设置必须为 NO。默认值为“否”,但出于性能原因,通常将其设置为“是”。

如果您已经在使用 -drawInContext:,那么您可以尝试使用 CGContextSetAlpha()。不过,通常情况下,您不会同时使用 -drawRect: 和图层。您通常让视图或图层进行绘图。

Set the -opacity of the layer. Remember that the layer's -opaque setting must be NO. The default is NO, but it's commonly set to YES for performance reasons.

If you're already doing -drawInContext:, then you can experiment with CGContextSetAlpha(). Generally, though, you don't use -drawRect: and layers at the same time. You usually let either the view or the layers do the drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文