一.UIToolBar
iOS7 及之前的版本可以使用UIToolBar 快速定義自己的毛玻璃效果
UIImageView *imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"register_bg.jpeg"]];
imageView.frame =self.view.frame;
[self.view addSubview:imageView];
UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,0, imageView.frame.size.width/2, imageView.frame.size.height)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[imageView addSubview:toolbar];
二.UIVisualEffectView類
在iOS8.0之后,蘋果新增了一個類UIVisualEffectView咒唆,可以快速實現(xiàn)毛玻璃效果济丘。官方文檔也提供了幾個類的說明
1、UIBlurEffect: 創(chuàng)建模糊效果资厉,也就是毛玻璃效果的類王污,可以設(shè)置風(fēng)格罢吃。
2、UIVibrancyEffect: 作用是放大和調(diào)整UIVisualEffectView內(nèi)容視圖的內(nèi)容的顏色,讓UIVisualEffectView的contentView中的內(nèi)容看起來更加生動
3昭齐、UIVisualEffect: 沒有任何方法尿招,只是充當(dāng)一個幫助UIVisualEffectView創(chuàng)建的對象,是UIBlurEffect和UIVibrancyEffect的父類
4阱驾、UIVisualEffectView:展示復(fù)雜的圖像效果就谜。
通常UIVibrancyEffect對象是與UIBlurEffect一起使用,主要用于處理在UIBlurEffect特效上的一些顯示效果里覆。
注意:
1丧荐、不要直接添加子視圖到UIVisualEffectView視圖中,而是應(yīng)該添加到UIVisualEffectView對象的contentView中
2喧枷、盡量避免將UIVisualEffectView對象的alpha值設(shè)置為小于1.0的值虹统,因為創(chuàng)建半透明的視圖會導(dǎo)致系統(tǒng)在離屏渲染時去對UIVisualEffectView對象及所有的相關(guān)的子視圖做混合操作弓坞。這不但消耗CPU/GPU,也可能會導(dǎo)致許多效果顯示不正確或者根本不顯示车荔。
UIImageView *imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"register_bg.jpeg"]];
imageView.frame =self.view.frame;
[self.view addSubview:imageView];
//iOS 8.0
* * 模糊效果的三種風(fēng)格
*
* @param UIBlurEffectStyle
*
* UIBlurEffectStyleExtraLight, //高亮
* UIBlurEffectStyleLight, //亮
* UIBlurEffectStyleDark //暗
* *
UIBlurEffect *blurEffect =[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *effectView =[[UIVisualEffectView alloc]initWithEffect:blurEffect];
effectView.frame = CGRectMake(imageView.frame.size.width/2,0,
imageView.frame.size.width/2, imageView.frame.size.height);
[self.view addSubview:effectView];