我看到iOS 9 setStatusBarHidden(_:withAnimation:)现在已被弃用,文档说应该改为使用,[UIViewController prefersStatusBarHidden]但是如果我仍然想用幻灯片动画隐藏状态栏,iOS 9中的替代方法是什么?
setStatusBarHidden(_:withAnimation:)
[UIViewController prefersStatusBarHidden]
参考preferredStatusBarUpdateAnimation,
preferredStatusBarUpdateAnimation
Gif
码
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 } }