Preferredstatusbarupdateanimation Being Ignored

setStatusBarHidden(_:withAnimation:) deprecated in iOS 9

Refer to preferredStatusBarUpdateAnimation,

Gif

Sample Image

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



Leave a reply



Submit