iOS端毛玻璃效果大致有以下四种方式
1.UIToolbar 7.0之前
2.UIBlurEffect 8.0开发的接口
3.CoreImage框架下CIFilter滤镜来做
4. 通过Accelerate.framework框架计算RGB色滴值的方式
1.UIToolbar
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,backview.frame.size.width,backview.frame.size.height)];
/*
UIBarStyleDefault 灰白色
UIBarStyleBlack 纯黑色 不设置透明度看不见
UIBarStyleBlackOpaque 纯黑色
UIBarStyleBlackTranslucent 纯黑色
*/
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.alpha = 0.67;
[backview addSubview:toolbar];
无论是灰白还是纯黑效果都不佳。
2.UIBlurEffect
UIBlurEffect *blureffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *effectview = [[UIVisualEffectView alloc]initWithEffect:blureffect];
effectview.frame = CGRectMake(0,0,backview.frame.size.width,backview.frame.size.height);
effectview.alpha = 0.7f;
[backview addSubview:effectview];
3.CoreImage
获取上下文
CIContext *context = [CIContext contextWithOptions:nil];
//把uiimage转换成CIImage
CIImage *ciImage = [CIImage imageWithCGImage:[UIImage imageNamed:@"timg-2.jpeg"].CGImage];
//滤镜
/*
CIBoxBlur,**
** CIDiscBlur,**
** CIGaussianBlur,**
** CIMaskedVariableBlur,**
** CIMedianFilter,**
** CIMotionBlur,**
** CINoiseReduction,**
** CIZoomBlur**
*/
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
//设置输入属性InputImage
[filter setValue:ciImage forKey:kCIInputImageKey];
//设置模糊程度inputRadius
[filter setValue:@(5) forKey: @"inputRadius"];
//设置输出属性
CIImage *result = [filter valueForKey:kCIOutputImageKey];
//将加过滤镜的图片输出
CGImageRef outImage = [context createCGImage: result fromRect:ciImage.extent];
//转换成uiimage
UIImage * blurImage = [UIImage imageWithCGImage:outImage];
backview.image = blurImage;
//
CGImageRelease(outImage);
第四种方式
小马哥的第三方库MCBlur库就是通过计算的方式
MCBlur
有兴趣可以去看看