四种方法:1.美工出图
2.coreImage框架,高斯效果
3.ToolBar,覆盖在view上边
//1.添加图片 self.imageView.image = [UIImage imageNamed:@"dog"]; //2.创建toolbar图层 UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,self.imageView.frame.size.width,self.imageView.frame.size.height)]; //3.设置toolbar模糊背景色调(默认白色) toolbar.barStyle = UIBarStyleDefault; //4.把图层覆盖到view上 [self.imageView addSubview:toolbar];
4.第三方框架DRNRealTimeBlur,继承封装好的view(轻量级,建议使用这种). 或第三方框架:LBBlurredImage
步骤:
1.github下载框架
2.拖入程序
3.编写代码:
#import "ViewController.h" #import "DRNRealTimeBlurView.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //1.随便创建一个imageView UIImage *image = [UIImage imageNamed:@"dog"]; UIImageView *imageView = [[UIImageView alloc]initWithImage:image]; //2.创建毛玻璃View DRNRealTimeBlurView *blurView = [[DRNRealTimeBlurView alloc]initWithFrame:imageView.frame]; //3.覆盖在imageview上. [self.view addSubview: imageView]; [self.view addSubview:blurView]; }
4.实现毛玻璃效果前后:
bug:如果在stroyBoard中出现毛玻璃图层无故遮挡其他图层问题,可先将毛玻璃图层调至最底层,在调回正确位置.即可修复.