在需要模糊的UIView上,添加一个UIVisualEffectView对象即可。
效果如下图:
代码如下:
UIImageView *imageview = [[UIImageView alloc] init];
imageview.frame = CGRectMake(10, 100, 300, 300);
imageview.image = [UIImage imageNamed:@"2"];
imageview.contentMode = UIViewContentModeScaleAspectFit;
imageview.userInteractionEnabled = YES;
[self.view addSubview:imageview];
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
effectview.frame = CGRectMake(0, 0, imageview.size.width/2, 300);
[imageview addSubview:effectview];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(10, 50, 100, 40);
[btn setTitle:@"btn" forState:UIControlStateNormal];
[effectview.contentView addSubview:btn];
iOS开发 swift技术交流QQ群361513739
iOS 8 模糊视图(毛玻璃效果)的简单实现UIVisualEffectView
原文地址:http://blog.csdn.net/oshuijue/article/details/40303949