美文网首页
iOS一键变黑白

iOS一键变黑白

作者: iOS_zy | 来源:发表于2023-05-15 14:13 被阅读0次

    直接上代码:

    #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
    

    想看详细的这里👉🏻

    相关文章

      网友评论

          本文标题:iOS一键变黑白

          本文链接:https://www.haomeiwen.com/subject/hwwmsdtx.html