简体   繁体   English

从CALayer面罩清除吗?

[英]Clear from CALayer mask?

I have a base layer, masked with a transparent mask layer. 我有一个基础层,用透明的蒙版层蒙版。

Mask layer have a sublayer, a transparent circle. 遮罩层有一个子层,一个透明的圆圈。 Works fine, the base layer is masked with the circle. 效果很好,基础层被圆圈遮盖了。

But I want to clear (zero out) the mask pixels with the circle. 但是我想用圆圈清除(清零)蒙版像素。 Not fill up with. 不满。 Can you get what I want? 你能得到我想要的吗?

How? 怎么样?


在此处输入图片说明

You can see the alpha channels of the mask images here. 您可以在此处查看蒙版图像的Alpha通道。


It is a 60 fps animation, so allocating instances/custom drawing every frame I think is not a solution, that would cut down performance. 这是一个60 fps的动画,因此我认为每帧分配实例/自定义图不是解决方案,这会降低性能。

It can be carried out via custom drawing only , in a CALAyer subclass (at least on iOS, having no any CIFilter for blending yet). 它只能通过自定义绘图在CALAyer子类中执行(至少在iOS上,尚无任何CIFilter可以混合)。 Exactly what I wanted to avoid. 正是我想要避免的。 :( :(

There are many ways, but the simplest seems to use the clear blend mode. 有很多方法,但是最简单的方法似乎是使用透明混合模式。

// Draw with Clear (!) blend mode.
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextSetFillColorWithColor(context, self.color.CGColor);
CGContextFillPath(context);

Don't even need any clipping or masking. 甚至不需要任何修剪或遮罩。 Maybe I'll gain performance by cache the path renderings. 也许我可以通过缓存路径渲染来提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM