iOS实现毛玻璃效果

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

使用core image
//生成一张毛玻璃图片
- (UIImage *)blur:(UIImage *)theImage
{
    CIContext *context = [CIContextcontextWithOptions:nil];
    CIImage *inputImage = [CIImageimageWithCGImage:theImage.CGImage];
   
    CIFilter *filter = [CIFilterfilterWithName:@"CIGaussianBlur"];
    [filter setValue:inputImageforKey:kCIInputImageKey];
    [filter setValue:[NSNumbernumberWithFloat:15.0]forKey:@"inputRadius"];//其中数值是模糊度(3~30,越大越模糊)
    CIImage *result = [filtervalueForKey:kCIOutputImageKey];
   
    CGImageRef cgImage = [contextcreateCGImage:resultfromRect:[inputImageextent]];
   
    UIImage *returnImage = [UIImageimageWithCGImage:cgImage];
    CGImageRelease(cgImage);
    return returnImage;
}

系统方法,iOS8以上
//方法一:系统方法,iOS8及以上可用
    if (!UIAccessibilityIsReduceTransparencyEnabled()) {
        UIBlurEffect *blurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView *blurEffectView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect];
        blurEffectView.frame = _imageView.bounds;
        [_imageView addSubview:blurEffectView];
    }

上述两种方法可以配合使用,效果可以增加光亮度