0%

动态显示隐藏状态栏

代码片段:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var hideStatusBar: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func btnAction(_ sender: Any) {
UIView.animate(withDuration: 0.5) { () -> Void in
self.hideStatusBar = self.hideStatusBar == true ? false : true
self.setNeedsStatusBarAppearanceUpdate()
}
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}

override var prefersStatusBarHidden: Bool {
return hideStatusBar
}

欢迎关注我的其它发布渠道