Swift 函数中隐藏的状态栏

Swift 函数中隐藏的状态栏,swift,hidden,statusbar,func,Swift,Hidden,Statusbar,Func,我想在隐藏导航栏和工具栏时隐藏状态栏 如果NavigationBar.hidden==false&&Toolbar.hidden==false{},如何使状态栏隐藏在中?? 我不知道该怎么做,我知道func会返回Statusbarhidden,但它在整个ViewController中,我想在func中隐藏它 谢谢你的帮助 func ImageTapGesture () { if NavigationBar.hidden == false && Toolbar.hidd

我想在隐藏导航栏和工具栏时隐藏状态栏

如果NavigationBar.hidden==false&&Toolbar.hidden==false{},如何使状态栏隐藏在
中??
我不知道该怎么做,我知道func会返回Statusbarhidden,但它在整个ViewController中,我想在func中隐藏它


谢谢你的帮助

  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

    }
}

一个兼容Swift 2.x的变通方法,用于制定您需要执行的操作:

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)
}
例如,要使用它,您可以启动:

hideStatusBar(-20.0)

在Swift语言下,你可以参考下面隐藏的代码,不需要动画效果就可以注释出来

    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
    }
也可以参考下面的演示链接,是我写项目要求的时候

Github:


希望我能帮助你。

你看到这个问题了吗?这可能会对你有所帮助-但这是整个应用程序的全部,你的整个ViewController,但要隐藏在func中,我什么也找不到。你知道我怎样才能在func中成功吗?谢谢你的帮助。