【发布时间】:2019-12-08 19:25:52
【问题描述】:
我想将 ViewController 呈现为弹出式 ViewController,它工作得很好,但问题是背景颜色变黑,但我想要一个透明的背景颜色。
let vc = self.storyboard?.instantiateViewController(withIdentifier: "ADLVC") as! ListViewController
//remove black screen in background
vc.modalPresentationStyle = .overCurrentContext
//add clear color background
vc.view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
//present modal
self.navigationController?.pushViewController(vc, animated: false)
使用此代码,我可以呈现一个透明的弹出 ViewCcontroller,但是当单击弹出 ViewController viewWillAppear() 中的关闭按钮时没有调用。
//create view controller
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SVC") as! SViewController
//remove black screen in background
vc.modalPresentationStyle = .overCurrentContext
//add clear color background
vc.view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
//present modal
self.present(vc, animated: false, completion: nil)
【问题讨论】:
标签: ios swift xcode cocoa-touch uiviewcontroller