ios - 如何将 ViewController 呈现为具有透明背景的弹出式 VC?
问题描述
我想将 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)
解决方案
在vc中,用于[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]
设置背景颜色和删除vc.modalPresentationStyle = .overCurrentContext
,希望它有效!
推荐阅读
- reactjs - 使用 react-svg-loader 导入 svg 文件时模块构建失败
- javascript - 在 React 中有条件地渲染组件
- c# - 如何在同一个按钮中使用鼠标和触摸事件?
- javascript - Ngrx 选择器:createSelector VS 纯 rxjs
- c# - 在 Unity 中用静态实例替换 SerializeField
- processing - 加工旋转线
- python - 将循环的输出向右移动
- smartsheet-api - 使用 Smartsheet API 删除大量行
- azure - 什么 Azure Kubernetes (AKS) “超时”会断开我集群中 Pod 的进出连接?
- csv - Python:将数据写入输出文件的多列