I have the following top status bar hide/ show code snippet with animation. It works well under iOS 14.5
private var additionalHeight: CGFloat {
if UIDevice.current.hasNotch {
return 0
} else {
return self.navigationController?.view.safeAreaInsets.top ?? 0
}
}
private var statusBarHidden: Bool = false {
didSet {
if statusBarHidden {
self.navigationController?.additionalSafeAreaInsets.top = additionalHeight
} else {
self.navigationController?.additionalSafeAreaInsets.top = 0
}
UIView.animate(withDuration: Constants.config_shortAnimTime) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
}
}
// https://medium.com/@badlands/unfortunately-this-also-applies-to-ipad-pro-which-have-non-zero-safeareainsets-e1aa0d002462
extension UIDevice {
/// Returns 'true' if the current device has a notch
var hasNotch: Bool {
if #available(iOS 11.0, *) {
// https://stackoverflow.com/a/57899013/72437
let keyWindow = UIWindow.key
// Case 1: Portrait && top safe area inset >= 44
let case1 = !UIDevice.current.orientation.isLandscape && (keyWindow?.safeAreaInsets.top ?? 0) >= 44
// Case 2: Lanscape && left/right safe area inset > 0
let case2 = UIDevice.current.orientation.isLandscape && ((keyWindow?.safeAreaInsets.left ?? 0) > 0 || (keyWindow?.safeAreaInsets.right ?? 0) > 0)
return case1 || case2
} else {
// Fallback on earlier versions
return false
}
}
}
iOS 14.5
However, when same code runs in iOS 15, the animation is broken. We use latest XCode 13.0
- During hide, there is no more "slide up" hide animation.
- During show, it will try to "push down" the entire view controller.
iOS 15
Does anyone has idea how to fix such animation in iOS 15, so that it behaves similar as iOS 14.5 ?