iOS一键变黑白

2023-05-15  本文已影响0人  iOS_zy

直接上代码:

#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

想看详细的这里👉🏻

上一篇下一篇

猜你喜欢

热点阅读