[英]How to extension UIViewController for hide and show StatusBar in Swift
I use isHideStatusBar(true) and override two essential props for hide and show StatusBar in viewController 我使用isHideStatusBar(true)并覆盖了viewController中隐藏和显示StatusBar的两个基本道具
var statusBarShouldBeHidden = false
override var prefersStatusBarHidden: Bool {
return statusBarShouldBeHidden
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}
func isHideStatusBar(_ bool: Bool, _ delay : CFTimeInterval = 0){
statusBarShouldBeHidden = bool
UIView.animate(withDuration: 0.4, delay: delay, options: [], animations: {
self.setNeedsStatusBarAppearanceUpdate()
}) { (finished) in
}
}
how to put some line of this code in to UIViewController
extension
? 如何将这段代码的某些行放入UIViewController
extension
?
Can be with a subclass 可以带有子类
class MainViewController: UIViewController {
var statusBarShouldBeHidden = false
override var prefersStatusBarHidden: Bool {
return statusBarShouldBeHidden
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}
func isHideStatusBar(_ bool: Bool, _ delay : CFTimeInterval = 0){
statusBarShouldBeHidden = bool
UIView.animate(withDuration: 0.4, delay: delay, options: [], animations: {
self.setNeedsStatusBarAppearanceUpdate()
}) { (finished) in
}
}
}
class ViewController: MainViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
isHideStatusBar(true)
}
}
Extension ability is limited to contain stored properties & overrided methods 扩展能力仅限于包含存储的属性和覆盖的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.