简单来说就是用UIBlurEffect和UIBlurEffectView做的一个效果,纯粹记录,如果对有幸看到的朋友们没有帮助的话,我先道个歉啦
1 - (void)viewDidLoad {
2 [super viewDidLoad];
3 // Do any additional setup after loading the view, typically from a nib.
4 //创建一张图片
5 UIImageView *imgV = [[UIImageView alloc]initWithFrame:self.view.frame];
6 //设置图片
7 imgV.image = [UIImage imageNamed:@"tree"];
8 //显示
9 [self.view addSubview:imgV];
将这个图片显示在ViewController上面之后,再把虚化图片的效果写成一个工具类(用category创建)
#import <UIKit/UIKit.h>
@interface UIView (BlurEffect)
//使用这个方法就能实现给这个视图加虚化效果
-(void)addBlurEffect:(CGRect)frame;
@end
#import "UIView+BlurEffect.h"
@implementation UIView (BlurEffect)
-(void)addBlurEffect:(CGRect)frame{
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//创建显示这个效果的虚化视图
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:effect];
//设置虚化的范围
effectView.frame = frame;
//添加虚化视图
[self addSubview:effectView];
}
@end
//调用虚化效果
[imgV addBlurEffect:imgV.frame];
最后在ViewController.m文件里面导入我们的工具类,再对imgV调用工具类里面的方法,在viewdidload里面添加如上代码
效果图:
待更