let mview = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)) //獲取delegate let delegate = UIAp ...
let mview = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
//獲取delegate
let delegate = UIApplication.shared.delegate as! AppDelegate
mview.backgroundColor = UIColor(white: 0.5, alpha: 0.8)
//添加tag
mview.tag = 1
//添加視圖
delegate.window?.addSubview(mview)
//通過tag 從window移除視圖
delegate.window?.viewWithTag(1)?.removeFromSuperview()