郑州iOS·點-毛玻璃效果

   

    毛玻璃效果

        先上图:

                  

      这里介绍一种比较简单,效率比较高的方法,在使用的时候只需要注意以下两点:

     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 {

    self.gsImgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值