在一個頁面中給一個半透明頁面:
// 跳到popWindow
let popVc = UIStoryboard(name: "ListViewStoryBoard", bundle: nil).instantiateViewController(withIdentifier: "PopWindowController") as! PopWindowController // 初始化
popVc.modalPresentationStyle = .overFullScreen // 這句代碼比較重要漾月,不然你會發(fā)現(xiàn)你的半透明頁面上面的控件也會半透明部默。
self.present(popVc, animated: true, completion: nil)
在你的半透明頁面中設(shè)置一下:
// 這個btn 是我在storyboard上面添加了一個btn覆蓋view甫匹,讓他在點擊灰色部分的時候走dismiss 方法
@IBOutlet weak var dismissBtn: UIButton! {
didSet{
dismissBtn.backgroundColor = UIColor.gray
dismissBtn.alpha = 0.5
}
}
// 在load方法中給view 設(shè)置透明也榄。這樣你的一個半透明的模態(tài)推送彈窗就搞定了
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.clear
}
當(dāng)然這是比較簡單的方法,也是我在項目中用的比較多的赌莺。這個界面的所有操作都可以通過代理回調(diào)到你需要的界面冰抢。。
***OC版本
PopViewController *popVc = [[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"PopViewController"];
self.definesPresentationContext = YES; //
UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:popVc]; // 導(dǎo)航欄帶過去艘狭。
navVc.view.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.5]; // 用這種方法設(shè)置顏色挎扰,子空間就不會透明了,不能直接通過[UIColor redColor]這種方式。
navVc.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:navVc animated:NO completion:nil];
**帶了導(dǎo)航過去巢音。記得在那邊隱藏**
---來自濤胖子的工作筆記