美文网首页iOS开发
iPad App开发获取statusBar高度失败问题

iPad App开发获取statusBar高度失败问题

作者: 左方 | 来源:发表于2021-08-05 11:19 被阅读0次

由于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?

相关文章

网友评论

    本文标题:iPad App开发获取statusBar高度失败问题

    本文链接:https://www.haomeiwen.com/subject/rmrmvltx.html