由于App实现了视频播放功能。在iPad中,实现AVPlayerViewController或AVPictureInPictureController时,会在UIApplication.shared.windows中添加一个PGHostedWindow。
这个Window是无法拿到statusBarManager的。所以更无法拿到statusBar高度。
所以原先代码是UIApplication.shared.windows.first,现在改为.last
//导航条高度
var STATUSBAR_HEIGHT: Float{
if #available(iOS 13.0, *) {
return Float(UIApplication.shared.windows.last?.windowScene?.statusBarManager?.statusBarFrame.size.height ?? 24)
} else {
return Float(UIApplication.shared.statusBarFrame.size.height)
}
}
参考资料:
1.What is PGHostedWindow in window hierarcy on iPad and how to prevent their creating?
2.How to get root view controller?
网友评论