I've tried to create a class in Swift, which autohides my UIStatusBar
and my navigationController
after 1 Second.
My problem is, that the StatusBar
is not going to disappear. This is what I got:
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)
}
You need to override this method in whichever view controller u want to hide uistatusbar.
override func prefersStatusBarHidden() -> Bool {
return true;
}
if its not work then try this:-
In Info.plist set View controller-based status bar appearance to NO
And call UIApplication.sharedApplication().statusBarHidden = true
hope this helps you.