gpt4 book ai didi

swift - UIStatusBar不会消失

转载 作者:行者123 更新时间:2023-11-30 10:11:10 24 4
gpt4 key购买 nike

我尝试在 Swift 中创建一个类,它会在 1 秒后自动隐藏我的 UIStatusBar 和我的 navigationController。我的问题是,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 的任何 View Controller 中重写此方法。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com