CAFilter是一个私有类,可以通过设置layer.filters
实现实时滤镜效果,不过私有类API有被拒风险。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| ///CAFilter @interface CAFilter : NSObject <NSSecureCoding, NSCopying> @property (readonly) NSString* type; @property (copy) NSString* name; @property (getter=isEnabled) BOOL enabled; @property BOOL cachesInputImage; + (instancetype)filterWithType:(NSString *)type; + (instancetype)filterWithName:(NSString *)name; + (NSArray <NSString *> *)filterTypes; - (instancetype)initWithType:(id)type; - (instancetype)initWithName:(id)name; - (void)setDefaults; @end
///五行代码实现APP黑白滤镜 self.window.layer.filters = @[({ CIFilter *filter = [NSClassFromString(@"CAFilter") filterWithName:@"colorSaturate"]; // 看是 CIFilter,实际上是 CAFilter [filter setValue:@0 forKey:@"inputAmount"]; filter; })];
目前支持的滤镜名(iOS 13)有以下这些: * multiplyColor * colorAdd * colorSubtract * colorMonochrome * colorMatrix * colorHueRotate * colorSaturate参数**inputAmount** * colorBrightness * colorContrast * colorInvert * compressLuminance * meteor * luminanceToAlpha * bias * distanceField * gaussianBlur参数**inputRadius** * luminanceMap * luminanceCurveMap * curves * averageColor * lanczosResize * pageCurl * vibrantDark * vibrantLight * vibrantColorMatrix
|