需求
蒙版遮蓋住現在的視圖,并有毛玻璃(高斯模糊)效果,如圖所示
高斯模糊.gif
實現方式
方法一:原生
代碼如下
/** style參數,蒙版的效果,可選:
* UIBlurEffectStyleExtraLight,
* UIBlurEffectStyleLight,
* UIBlurEffectStyleDark,
* UIBlurEffectStyleExtraDark ios10之后
* UIBlurEffectStyleRegular ios10之后
* UIBlurEffectStyleProminent ios10之后
*/
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *HUDView = [[UIVisualEffectView alloc] initWithEffect:blur];
HUDView.alpha = 0.9f;
HUDView.frame = CGRectMake(0, 0, YYScreenW, YYScreenH);
[self.view addSubview:HUDView];
效果圖
原生效果圖
的確有一定的虛化效果,但不明顯
方法二:DRNRealTimeBlurView框架(推薦使用)
要實現上面的需求,推薦使用DRNRealTimeBlurView框架,使用簡單,模糊效果好看,框架下載地址https://github.com/CoderJee/DRNRealTimeBlurView
解壓后需要里面的.h和.m文件共四個
071102.png
代碼:
//引頭文件
#import "DRNRealTimeBlurView.h"
DRNRealTimeBlurView *blurView = [[DRNRealTimeBlurView alloc] initWithFrame:CGRectMake(0, 0, YYScreenW, YYScreenH)];
[backImgView addSubview:blurView];
//backImgView是UIImageView,是頁面背景
//什么控件需要做模糊效果,就往什么控件上加,非常簡單
效果圖
框架效果圖