iOS一键变黑白

直接上代码:

#import "BlackWhiteManager.h"

#define GreyFilterTag 8691

@interface BlackWhiteManager()

@end

@implementation BlackWhiteManager

+ (void)addGreyFilterToView:(UIView *)view {
    CGRect r = view.bounds;
    if ([view isKindOfClass:[UIScrollView class]]){
        UIScrollView *s = (UIScrollView*)view;
        r = CGRectMake(0, 0, s.bounds.size.width, 9999);
    }
    UIView *greyView = [[UIView alloc] initWithFrame:r];
    greyView.userInteractionEnabled = NO;
    greyView.tag = GreyFilterTag;
    greyView.backgroundColor = [UIColor lightGrayColor];
    greyView.layer.compositingFilter = @"saturationBlendMode";
    greyView.layer.zPosition = FLT_MAX;
    [view addSubview:greyView];
}

+ (void)removeGreyFilterToView:(UIView *)view {
    UIView *greyView = [view viewWithTag:GreyFilterTag];
    if (greyView){
        [greyView removeFromSuperview];
    }
}
@end

想看详细的这里👉🏻

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容