我无法创建单独的自定义popview ..所以我尝试了下面提到的答案之一
这是 Storyboard View 层次结构
popBG view background colour is black with alpha = 0.3
这是代码:class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var popViewtop: UIView!
@IBOutlet weak var testTable: UITableView!
@IBOutlet weak var popView: UIView!
@IBOutlet weak var popBG: UIView!
override func viewDidLoad() {
super.viewDidLoad()
popViewtop.isHidden = true
}
@IBAction func testBtn(_ sender: Any) {
popViewtop.isHidden = false
}
@IBAction func btnPop(_ sender: Any) {
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "NewZoomAddressViewController") as! NewZoomAddressViewController;
popViewtop.isHidden = true
self.navigationController?.pushViewController(viewController, animated: true);
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
}现在 tableview 和 button 没有显示透明.. 只有 popbg 和 popview 来了.. 我错过了什么..
其实我需要这样的 : 一些深色的总背景 View 和以白色突出显示的弹出 View
最佳答案
view
的 subView 的 alpha 值变化,包括 popupView
popupView
view
的 subView 的 alpha 值没有变化,包括 popupView
popupView
是 view
的 subview , view
的 alpha 值会影响其 subview 的 alpha。view.addSubview(popupView)
您当前的结构:RootView->Subviews //Changing RootView alpha effects Subviews.
解决方案是
popupView
不是 view
的 subview ,你用它来显示颜色变化需要一个容器 View 来与
popupView
分开// backgroundColorChangeContainerView add other views ( tableView ... )
view.addSubview(backgroundColorChangeContainerView)
view.addSubview(popupView)
关于ios - 如何在swift中更改除弹出 View 外的总屏幕背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62828561/