使用core image
//生成一张毛玻璃图片
- (UIImage *)blur:(UIImage
*)theImage
{
CIContext *context = [CIContext
contextWithOptions:nil];
CIImage *inputImage = [CIImage
imageWithCGImage:theImage.CGImage];
CIFilter *filter = [CIFilter
filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage
forKey:kCIInputImageKey];
[filter setValue:[NSNumber
numberWithFloat:15.0]
forKey:@"inputRadius"];
CIImage *result = [filter
valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context
createCGImage:result
fromRect:[inputImage
extent]];
UIImage *returnImage = [UIImage
imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return returnImage;
}
系统方法,iOS8以上
//方法一:系统方法,iOS8及以上可用
if (!UIAccessibilityIsReduceTransparencyEnabled())
{
UIBlurEffect *blurEffect = [UIBlurEffect
effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView
alloc]initWithEffect:blurEffect];
blurEffectView.frame = _imageView.bounds;
[_imageView addSubview:blurEffectView];
}