viewcontroller1 為當(dāng)前視圖控制器佛纫, viewcontroller2 為需要在 viewcontroller1上展示的底部透明的視圖控制器
1.在viewcontroller1 要觸發(fā)該功能的事件添加如下代碼
Viewcontroller2 *vc2 = [[Viewcontroller2 alloc]init];
vc2.view.backgroundColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:0.2];
//注意:要展示的那個(gè)底色透明的視圖控制器 設(shè)置透明屬性必須在這里提前設(shè)置
[self presentViewController:vc2 animated:YES completion:nil];
2.在 vc2 中的viewDidLoad 方法中添加
self.modalPresentationStyle = UIModalPresentationCustom;
上面的代碼片段在ios8.0系統(tǒng)上是沒有任何錯(cuò)誤的的宛乃,對(duì)于ios7.0系統(tǒng)這時(shí)候彈出的視圖會(huì)存在背景界面為黑色的情況缝裁,所以作如下修改:
if(iOS(8.0)){
viewcontroller2.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}else{
viewcontroller1.modalPresentationStyle = UIModalPresentationCurrentContext;
}
顯示界面的背景顏色直接在要彈出的界面里面修改:
viewcontroller2.view.backgroundColor=[UIColorcolorWithRed:0green:0 blue:0 alpha:0.5];