ios - 如何使用不同的混合模式渲染 CALayer,比如屏幕或乘法?

标签 ios iphone core-animation

我有一个 UIImageView 并希望它以特定的混合模式显示。我知道 iPhone 有不同的混合模式,可能可以用很多 CG 代码来实现……但也许 UIImageViewCALayer 有一个不错的方法?

最佳答案

将 View 层的 compositingFilter 设置为受支持的混合模式字符串。从文档中,层的 compositingFilter

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

要获取 Core Image 过滤器列表,打印出由 kCICategoryCompositeOperation 定义的过滤器名称

[CIFilter filterNamesInCategory:kCICategoryCompositeOperation]

或直接作为

[CIFilter filterNamesInCategory:@"CICategoryCompositeOperation"]

该数组将包含形式为 Core Image 的过滤器

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

要使用 CIMultiplyBlendMode,请将“multiplyBlendMode”设置为图层上的合成过滤器

self.layer.compositingFilter = @"multiplyBlendMode";

关于ios - 如何使用不同的混合模式渲染 CALayer,比如屏幕或乘法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2939324/

相关文章:

iOS 开发者门户 : Cannot add or edit app ids and profiles (greyed out)

ios - Apple 框架 ISA 分类

iphone - 更改 xcode 项目路径时出现小写路径问题

iphone - 将 NSDate 设置为特定日期、时间和时区

ios - Xcode( swift ): Changing UIButton attributes in a different UIViewController class than that in which they were referenced

ios - 如何忽略 UIGestureRecognizer 触摸?

iphone - 如何在iPhone APP中缓存JSON数据以供离线阅读?

ios - 旋转的 Spring 动画在它开始的地方结束

swift - CAAnimation 路径仅在 View /图层的范围内

ios - UIImage 中的绘图被扭曲