setStatusBarHidden(_:withAnimation:) deprecated in iOS 9
Refer to preferredStatusBarUpdateAnimation
,
Gif
Code
class ViewController: UIViewController {
var isHidden:Bool = false{
didSet{
UIView.animate(withDuration: 0.5) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
}
}
@IBAction func clicked(sender: AnyObject) {
isHidden = !isHidden
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{
return .slide
}
override var prefersStatusBarHidden: Bool{
return isHidden
}
}
UIScrollView dynamic status bar
Solution I found (More of a workaround)
declare a boolean called hidden.
Then I overrode these methods:
func scrollViewDidScroll(scrollView: UIScrollView){
let xOffset = scrollView.contentOffset.x;
if(xOffset > scrollView.contentSize.width/4)
{
if hidden == true {
print("\nShow status bar\n")
hidden = false
UIView.animateWithDuration(0.3, animations: {
self.setNeedsStatusBarAppearanceUpdate()
})
}
} else
{
print("\nHide Status Bar\n")
hidden = true
UIView.animateWithDuration(0.2, animations: {
self.setNeedsStatusBarAppearanceUpdate()
})
}
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
if hidden == false {
return UIStatusBarAnimation.Fade
} else {
return UIStatusBarAnimation.Slide
}
}
override func prefersStatusBarHidden() -> Bool {
print("\nstatus Bar Changed to hidden = \(hidden)\n")
return hidden
}
It fades the status bar in once you've at least scrolled half way, and slides the status bar back up once you've gone back half way again.
Hiding a statusbar in specifc viewcontroller
In your info.plist
add row called View controller-based status bar appearance
and set it to NO
.
Then call the following code in viewDidload
and it should hide with animation:
UIApplication.sharedApplication().statusBarHidden = true
After that you will be getting a warning printed in the console like :
CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Just ignore it, as they said its a bug from apple and for reference see here:
How can I set CG_CONTEXT_SHOW_BACKTRACE environmental variable?
Javascript: Expand / Collapse Multiple DIV's with simple code?
This will work.
$('.show_hide').click(function(){
$(this).next('.slidingDiv').slideToggle();
return false;
});
jsfiddle - http://jsfiddle.net/ABrunkhorst/vFnqp/1/
Related Topics
Tableview Image Content Selection Color
How to Use The Delegates with Nskeyedunarchiver
Is There Any Difference at All Between Suffix(From:) and Dropfirst(_:)
How to Draw a Line Between Two Points Over an Image in Swift 3
Difference Between Object(Forkey:) and Value(Forkey:) in Userdefaults
How to Create a Pulse Effect on an Skspritenode
Convert from Nsdictionary to [String:Any]
How to Detect Hash Changes in Wkwebview
Extra Argument Userinfo in Call
Vapor 3 - How to Check for Similar Email Before Saving Object
"'Init' Is Deprecated" Warning After Swift4 Convert
Wait for Download Task to Finish in Nsurlsession
Navigation Bar Items After Push from Swiftui to UIkit
Preferredstatusbarupdateanimation Being Ignored
Swift - Measurement Convert(To:) Miles to Feet Gives Wrong Result
Crash Casting Wknsurlrequest As? Other Type
Answers by Crashlytics - Adding Custom Event
How to Check If Optional Is Not Nil and Property Is True in One Expression