[英]How to hide and show UIViewController button in AppDelegate? - Swift
[英]How to extension UIViewController for hide and show StatusBar in Swift
我使用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
}
}
如何將這段代碼的某些行放入UIViewController
extension
?
可以帶有子類
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)
}
}
擴展能力僅限於包含存儲的屬性和覆蓋的方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.