iOS简单实现毛玻璃效果

iOS8之后有一个类 UIVisualEffectView

// 毛玻璃
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    img.userInteractionEnabled = YES;
    img.image = [UIImage imageNamed:@"effect"];
        [self.view addSubview:img];
//    UIBlurEffectStyleExtraLight,
//    UIBlurEffectStyleLight,
//    UIBlurEffectStyleDark
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    effectview.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    effectview.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];
    [effectview addGestureRecognizer:tap];
    effectview.alpha = 1.0; // 根据需要设置渲染的程度
    [self.view addSubview:effectview];

 

posted @ 2016-07-05 16:11  多两口  阅读(211)  评论(0)    收藏  举报