毛玻璃效果
先上图:
这里介绍一种比较简单,效率比较高的方法,在使用的时候只需要注意以下两点:
1.[NS_CLASS_AVAILABLE_IOS(8_0)];
2.建议不要使用这个UIVisualEffectView类父类的 alpha 属性.
UIVisualEffectView: 视觉效果视图类
父类是UIView,遵循NSSecureCoding协议
有两个属性:(UIView *)contentView 和 (UIVisualEffect *)effect
需要注意的是:不要将自定义的子视图直接添加到这个类的对象上,用它原生的contentView就好;
另外系统还提供了两个初始化方法:
- (instancetype)initWithEffect:(nullable UIVisualEffect *)effect NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
这里拓展一下 NS_DESIGNATED_INITIALIZER,有位码友分析的特别到位,分享至此供大伙儿参考延伸:https://yq.aliyun.com/articles/5847
以码会友,还望众大神多多指点~
毛玻璃实现代码如下:
.m
@interface
@property (nonatomic, strong)UIImageView *gsImgView;
@end
@implementation
- (void)viewDidLoad {
[super viewDidLoad];
[self configureGsImgView];
}
- (void)configureGsImgView {
NSString *urlStr = @"http://mg.soupingguo.com/bizhi/big/10/375/018/10375018.jpg";
[_gsImgView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
[self.view addSubview:self.gsImgView];
UIVisualEffectView *VEView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
VEView.frame = CGRectMake(0, 0, _gsImgView.frame.size.width, _gsImgView.frame.size.height);
[self.gsImgView addSubview:VEView];
@end