在iOS 9中不推荐使用setStatusBarHidden(_:withAnimation :) [英] setStatusBarHidden(_:withAnimation:) deprecated in iOS 9

查看:2883
本文介绍了在iOS 9中不推荐使用setStatusBarHidden(_:withAnimation :)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 9中看到 setStatusBarHidden(_:withAnimation:)现已弃用,文档说使用 [UIViewController prefersStatusBarHidden] 相反,但如果我还想用幻灯片动画隐藏状态栏,iOS 9中的替代方案是什么?

I see that in iOS 9 setStatusBarHidden(_:withAnimation:) is now deprecated and the documentation says to use [UIViewController prefersStatusBarHidden] instead but what is the alternative in iOS 9 if I still want to hide the status bar with a slide animation?

推荐答案

参考 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
    }
 }

这篇关于在iOS 9中不推荐使用setStatusBarHidden(_:withAnimation :)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆