直接上代码:
#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