Swift 在UIWindow 上添加並移除 view


 

 

     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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM