ios - 如何在swift中更改除弹出 View 外的总屏幕背景颜色

标签 ios swift xcode uiview uicolor

我无法创建单独的自定义popview ..所以我尝试了下面提到的答案之一
这是 Storyboard View 层次结构
enter image description here

 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 来了.. 我错过了什么..
enter image description here
其实我需要这样的 : 一些深色的总背景 View 和以白色突出显示的弹出 View
enter image description here

最佳答案

  • 如果要查看 alpha 值,
  • view的 subView 的 alpha 值变化,包括 popupView
  • 如果要查看背景颜色,包括 popupView
  • view的 subView 的 alpha 值没有变化,包括 popupViewpopupViewview 的 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/

    相关文章:

    ios - iOS IPv6下无声音问题

    ios - url.isFileReferenceURL() 在 IOS 中为本地文件返回 false

    ios - 如何在 ios (Swift 3) 中将 MKPlacemark 存储到 Realm?

    ios - 如何在我的设备上以发布/分发模式测试应用程序?

    iphone - 使用仪器来查找代码中堆栈的溢出

    ios - Obj-C-显示对应数组中每个单元格的正确数据

    ios - 是否可以在IOS模拟器中模拟本地联系人以外的其他联系人

    ios - sharedApplication' 不可用 : not available on iOS (App Extension) - Use view controller based solutions where appropriate instead

    ios - 在 iOS 中操作 XML 文件

    swift - UITabBarController 中的 Controller