代码之家  ›  专栏  ›  技术社区  ›  SanMu

模态视图控制器子视图

  •  0
  • SanMu  · 技术社区  · 6 年前

    我已经尝试将子视图的alpha设置为1,但它不会改变外观。

    class GameOverViewController: UIViewController {
        private let restart = UIButton(type: .custom)
        private let mainmenu = UIButton(type: .custom)
    
        override func viewDidLoad() {
            //displays view controller modally
            super.viewDidLoad()
            self.view.backgroundColor = .white
            self.view.alpha = 0.6
            self.modalPresentationStyle = .overCurrentContext
    
            //add dialogue box
            let dialoguebox = UIView(frame: CGRect(origin: CGPoint(x: self.view.frame.width / 2, y: self.view.frame.height / 2), size: CGSize(width: self.view.frame.width / 2, height: self.view.frame.height / 2)))
            dialoguebox.backgroundColor = .red
            dialoguebox.center = self.view.center
            dialoguebox.alpha = 1
            self.view.addSubview(dialoguebox)
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   matt    6 年前

        self.view.alpha = 0.6
    

    这影响到 alpha 这一观点 及其所有子视图 ,包括您的对话框。不能使对话框具有完全有效的不透明度,因为它继承了对话框的透明度 self.view .

    self.view.backgroundColor 一些透明度。所以不要让它纯洁 .white 白色 以及一些较低的alpha值。