我的屏幕上有按钮,标签,工具栏,导航栏和状态栏。我尝试进行自定义手势点击,以隐藏/显示此用户界面以清除屏幕。我可以使用UIView.animate(withDuration:0.5)帮助隐藏所有这些UI。但是,当我添加他们的状态栏时,我的导航栏和工具栏开始不显示动画就隐藏起来,而是随动画一起显示。我究竟做错了什么?
我用它来隐藏/显示状态栏:
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .fade
}
override var prefersStatusBarHidden: Bool {
return navigationController?.isStatusBarHidden ?? false
}
,然后在另一个函数中调用它:
UIView.animate(withDuration: 0.5) {
self.setNeedsStatusBarAppearanceUpdate()
self.navigationController?.isStatusBarHidden.toggle()
}
在这里,我的按钮/标签,导航栏,工具栏的隐藏/显示功能
public extension UIView {
func show(duration: TimeInterval = 0.5) {
guard isHidden else { return }
alpha = 0
isHidden = false
UIView.animate(withDuration: duration, animations: {
self.alpha = 1
})
}
func hide(duration: TimeInterval = 0.5) {
UIView.animate(withDuration: duration, animations: {
self.alpha = 0
}) { [weak self] _ in
self?.isHidden = true
}
}
}