Add a UIView above all, even the navigation bar

前端 未结 17 1681
悲&欢浪女
悲&欢浪女 2020-11-29 15:36

I want to display, above any other views, even the navigation bar, a kind of \"pop-up\" view that looks like this:

  • full screen black background with a 0.5 alph
17条回答
  •  爱一瞬间的悲伤
    2020-11-29 16:01

    Note if you want add view in Full screen then only use below code

    Add these extension of UIViewController

    public extension UIViewController {
       internal func makeViewAsFullScreen() {
          var viewFrame:CGRect = self.view.frame
          if viewFrame.origin.y > 0 || viewFrame.origin.x > 0 {
            self.view.frame = UIScreen.main.bounds
          }
       }
    }
    

    Continue as normal adding process of subview

    Now use in adding UIViewController's viewDidAppear

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
         self.makeViewAsFullScreen()
    }
    

提交回复
热议问题