iOS开发——毛玻璃透明
主要实现的代码如下:
self.rateInfoView是定义好的控制属性控件
可以改变透明度的值来改变毛玻璃透明的效果
// 虚拟交易费率弹窗 - (void)showRateInfo{ self.rateInfoView = [[UIView alloc]initWithFrame:self.windowView.frame]; // rateInfoView.backgroundColor = [UIColor blackColor]; self.rateInfoView.alpha = 0.f; [self.view addSubview:self.rateInfoView]; // 创建需要的毛玻璃特效类型 UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; // 毛玻璃view 视图 UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; //添加到要有毛玻璃特效的控件中 effectView.frame = self.windowView.frame; [self.rateInfoView addSubview:effectView]; //设置模糊透明度 effectView.alpha = .8f; UIImageView *rateImage = [[UIImageView alloc]initWithFrame:CGRectMake(Width*0.1, (Height-Width*0.8*1.11)/2+20, Width*0.8, Width*0.8/1.11)]; rateImage.image = [UIImage imageNamed:@"虚拟费率弹窗"]; [self.rateInfoView addSubview:rateImage]; UIButton *closeInfo = [UIButton buttonWithType:UIButtonTypeCustom]; closeInfo.frame = CGRectMake(Width*0.9-22-12, (Height-Width*0.8*1.11)/2+20+12, 22, 22); [closeInfo setImage:[UIImage imageNamed:@"cancel"] forState:UIControlStateNormal]; [closeInfo addTarget:self action:@selector(closeRate) forControlEvents:UIControlEventTouchUpInside]; [self.rateInfoView addSubview:closeInfo]; [UIView animateWithDuration:0.2 animations:^{ self.rateInfoView.alpha = 1.0f; }]; } - (void)closeRate{ [self.rateInfoView removeFromSuperview]; }
效果图: