我尝试在Swift中创建一个类,该类在1秒后自动隐藏我的UIStatusBarnavigationController
我的问题是StatusBar不会消失。这是我得到的:

override func viewDidLoad() {
    super.viewDidLoad()
    NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "prefersStatusBarHidden", userInfo: nil, repeats: false)
}
override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
    }

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
    return UIStatusBarAnimation.Fade
}

override func prefersStatusBarHidden() -> Bool {
    if (barcounter == 0){
        hide()
        barcounter = 1
        return true
    }
    else {
        show()
        barcounter = 0
        return false
    }
}

@IBAction func picturePressed(sender: AnyObject) {
    prefersStatusBarHidden()
}

func hide(){

    UIView.animateWithDuration(1, delay: 1, options: UIViewAnimationOptions.CurveEaseOut, animations: {

        self.navigationController?.navigationBar.alpha = 0.0

        }, completion: nil)

}

func show(){
    UIView.animateWithDuration(1, delay: 1, options: UIViewAnimationOptions.CurveEaseOut, animations: {

        self.navigationController?.navigationBar.alpha = 1.0

        }, completion: nil)

}

最佳答案

无论您要隐藏uistatusbar的哪个视图控制器,都需要重写此方法。

override func prefersStatusBarHidden() -> Bool {
    return true;
}


如果不起作用,请尝试以下操作:-

In Info.plist set View controller-based status bar appearance to NO

And call UIApplication.sharedApplication().statusBarHidden = true


希望这对您有帮助。

关于swift - UIStatusBar不会消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32989015/

10-09 06:31