1

I would like to hide the Statusbar when i hide Navigationbar and Toolbar.

How i can make that that the Statusbar is hidden in if NavigationBar.hidden == false && Toolbar.hidden == false{} ?? I have no idea how i can make that, i know the func to return the Statusbarhidden but thats in the whole ViewController and i would to hide it in the func.

Thanks for your Help.

  func ImageTapGesture () {
    if NavigationBar.hidden == false && Toolbar.hidden == false{
        NavigationBar.hidden = true
        Toolbar.hidden = true

    } else if NavigationBar.hidden == true && Toolbar.hidden == true  {
        NavigationBar.hidden = false
        Toolbar.hidden = false

    }
}
Hindus
  • 35
  • 1
  • 5
  • Did you see this question ? This might help you - http://stackoverflow.com/questions/18979837/how-to-hide-ios-status-bar – BLC Mar 24 '16 at 12:57
  • But thats all for the complete app your for the whole ViewController but to hide it in a func i have nothing find. Have you an idea how i can make it in a func ? – Hindus Mar 24 '16 at 13:17

2 Answers2

1

Under the Swift language, you can refer to the following code hidden, don't need animation effects can be commented out.

    var isHidden:Bool = false

    @IBAction func clicked(_ sender: AnyObject) {
        isHidden = !isHidden
        UIView.animate(withDuration: 0.5, animations: { () -> Void in
            self.setNeedsStatusBarAppearanceUpdate()
        }) 
    }
    override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
        return UIStatusBarAnimation.slide
    }
    override var prefersStatusBarHidden : Bool {
        return isHidden
    }

Can also refer to the following link to the Demo, is a time I write the project requirements.

Github:https://github.com/ReverseScale/HiddenStatusBar

Wish I could help you.

Tim
  • 1,528
  • 1
  • 11
  • 8
0

A Swift 2.x compatible workaround to make what do you need to do :

func hideStatusBar(yOffset:CGFloat) { // -20.0 for example
    let statusBarWindow = UIApplication.sharedApplication().valueForKey("statusBarWindow") as! UIWindow
    statusBarWindow.frame = CGRectMake(0, yOffset, statusBarWindow.frame.size.width, statusBarWindow.frame.size.height)
}

func showStatusBar() {
    let statusBarWindow = UIApplication.sharedApplication().valueForKey("statusBarWindow") as! UIWindow
    statusBarWindow.frame = CGRectMake(0, 0, statusBarWindow.frame.size.width, statusBarWindow.frame.size.height)
}

To use it for example you can launch:

hideStatusBar(-20.0)
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133