ios8 毛半透明效果(UIVisualEffectView)

來源:互聯網
上載者:User

標籤:

 

 

首先有這樣4個類

UIVisualEffect

UIBlurEffect

UIVibrancyEffect

UIVisualEffectView

 

繼承關係

UIVisualEffect : NSObject

 |—> UIBlurEffect 

 |—> UIVibrancyEffect

UIVisualEffectView : UIView

 

來自百度翻譯(這樣是學不好編程的)

Visual

視覺的(視力的); 

 

Blur

n. 汙跡,汙斑;   模糊不清的事物;   曖昧不明;  

vt.& vi. 塗汙,弄髒;   (使)變模糊,(使)難以區分;  

 

Effec

n. 影響;   效果;   印象;   所有物;  

vt. 使發生;   引起;   產生(效果); 

 

Vibrancy

n. 震動;   振響;   活躍;   活力;  

 

初始化

typedef NS_ENUM(NSInteger, UIBlurEffectStyle) {
UIBlurEffectStyleExtraLight,//高亮的風格
UIBlurEffectStyleLight,//亮化的風格
UIBlurEffectStyleDark//暗化的風格
} ;

 

UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

UIVisualEffectView *vise = [[UIVisualEffectView alloc] initWithEffect:blur];

 

 然後這樣
    UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];    UIImage * img = [UIImage imageNamed:@"1.jpg"];    UIVisualEffectView * effectView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];    //設定虛化度    effectView.alpha=1.0;    effectView.frame=CGRectMake(0, 0, self.view.frame.size.width, 200);    view.image=img;    [view addSubview:effectView];    [self.view addSubview:view];

結果是這樣(現在還沒有文字呢,後面的代碼中會有)

 

還有一種樣式

 

注意文字,這裡是這樣初始化的

1.

    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];        UIVibrancyEffect *vibrancy = [UIVibrancyEffect effectForBlurEffect:blur];        UIVisualEffectView *vise = [[UIVisualEffectView alloc] initWithEffect:vibrancy];

2. 你需要把標籤添加到 contentView 上

[vise.contentView addSubview:lab];

 

UIBlurEffect是對整個背景進行虛化,UIVibrancyEffect是對添加的標籤等附件進行背景虛化。注意,這些附件,必須加在UIVisualEffectView的contentView裡,否則將不起任何作用。

 

 

 

ios8 毛半透明效果(UIVisualEffectView)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.