How to render a CALayer with a different blending mode, like screen or multiply?

前端 未结 2 1840
执念已碎
执念已碎 2021-02-08 03:53

I have a UIImageView and want it to be displayed with a specific blend mode. I know the iPhone has different blend modes, and it\'s probably possible to do it with

2条回答
  •  鱼传尺愫
    2021-02-08 04:35

    Set the compositingFilter of a view's layer to a supported blend mode string. From the docs, a layer's compositingFilter is

    A CoreImage filter used to composite the layer and the content behind it.

    To obtain a list of Core Image filters, print out the filter names defined by a kCICategoryCompositeOperation

    [CIFilter filterNamesInCategory:kCICategoryCompositeOperation]
    

    or directly as

    [CIFilter filterNamesInCategory:@"CICategoryCompositeOperation"]
    

    The array will include Core Image filters in the form

    {
       CIColorBlendMode,
       CIColorBurnBlendMode,
       CIColorDodgeBlendMode,
       CIMultiplyBlendMode,
       ...
    }
    

    To use the CIMultiplyBlendMode, set "multiplyBlendMode" as the compositingFilter on the layer

    self.layer.compositingFilter = @"multiplyBlendMode";
    

提交回复
热议问题