无法在AVPlayerViewController的纵向模式下隐藏状态栏 [英] Can't hide status bar in AVPlayerViewController's portrait mode

查看:100
本文介绍了无法在AVPlayerViewController的纵向模式下隐藏状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序首先显示带有一堆按钮的UICollectionView,这些按钮以自定义"Over Full Screen"设置在AVPlayerViewController的子类中打开. 在我的Info.plist中,UIViewControllerBasedStatusBarAppearance设置为YES.

I'm developing an app that first presents a UICollectionView with a bunch of buttons that modally open a subclass of AVPlayerViewController with a custom "Over Full Screen" segue. UIViewControllerBasedStatusBarAppearance is set to YES in my Info.plist.

这是Interface Builder中所有视图控制器的小屏幕截图(抱歉,不得不缩小):

Here's a small (had to zoom out, sorry) screenshot of all the view controllers in Interface Builder:

segue是在IB中定义的.当用户点击集合视图单元格时,我使用performSegueWithIdentifier()来执行segue.

The segue was defined in IB. When the user taps a collection view cell, I use performSegueWithIdentifier() to, well, perform the segue.

我现在遇到的问题是:

The problem I'm now experiencing is this:

为什么在横向模式下状态栏与播放控件一起隐藏,而在纵向模式下却相反?

Why does the status bar hide along with the playback controls in landscape mode, while doing the exact opposite in portrait mode?

在我的AVPlayerViewController的子类中,使preferredsStatusBarHidden()返回true不会执行任何操作.有什么作用?

Making prefersStatusBarHidden() return true in my subclass of AVPlayerViewController doesn't do anything. What gives?

推荐答案

只想出一个解决方案:

extension UINavigationController {
    public override func childViewControllerForStatusBarHidden() -> UIViewController? {
        return self.childViewControllers.last
    }

    public override func childViewControllerForStatusBarStyle() -> UIViewController? {
        return self.childViewControllers.last
    }
}

是的,只需为应用中的所有导航视图控制器覆盖这两个功能即可.我认为这是黑客行为,而不是此问题的正确"解决方案,因此请谨慎使用.

Yup, just override those two functions for all Navigation View Controllers in your app. I consider this to be a hack and not the 'correct' solution to this problem, so use this with caution.

据我所知,这永远不会失败.在我的应用中,每个导航VC都只有一个子VC,但只有YMMV.

As far as I can tell, this should never fail. In my app, every Navigation VC has exactly one child VC, but YMMV.

这篇关于无法在AVPlayerViewController的纵向模式下隐藏状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆