IOS7 Status bar hide/show on select controllers

后端 未结 5 1439
北荒
北荒 2020-12-01 01:46

I would like to show and hide the Status bar on some controllers. Can this be done or is it more of an overall app setting.

I have seen many posts/questions about th

5条回答
  •  情书的邮戳
    2020-12-01 02:46

    You can also show/hide the status bar in an animation block, by putting animation code inside didSet property of variable that describes whether it should be shown or hidden. When you set a new value for the statusBarHidden Bool, this automatically triggers the animated updating of the status bar over the duration you have chosen.

    /// Swift 3 syntax: 
    
    var statusBarHidden: Bool = true {
        didSet {
            UIView.animate(withDuration: 0.5) { () -> Void in
                self.setNeedsStatusBarAppearanceUpdate()
            }
        }
    }
    
    override var prefersStatusBarHidden: Bool {
        return statusBarHidden
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)        
        statusBarHidden = false // show statusBar, animated, by triggering didSet block
    }
    

提交回复
热议问题