Fay*_*waz 4 autorotate ios swift avplayerviewcontroller
我正在开发一个仅在纵向模式下的 iOS 应用程序,并且运行良好。
问题是我在 navigationController 之上呈现AVPlayerViewController(两者都是以编程方式创建的)。该播放器支持所有轮换(我不知道为什么!)。
我想将其修复为纵向模式,就像应用程序的其他部分一样。
我们怎样才能做到这一点?
创建继承自 AVPlayerViewController 的新类并实现支持的接口方法,如下所示。之后,只需创建您创建的类的对象,而不是初始化 AVPlayerViewController 的对象。
\n\nclass MyPortraitVideoController: AVPlayerViewController {\n\n\n override var supportedInterfaceOrientations: UIInterfaceOrientationMask {\n return .portrait\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n
\n编辑添加:
请注意,文档AVPlayerViewController说明:
\n\n\n重要
\n
不要子类化 AVPlayerViewController。不支持重写此\n class\xe2\x80\x99s 方法,并会导致未定义的行为。
由于这是公认的答案,我认为OP已经尝试过并且它有效,但我认为我应该在这里添加一个注释,以确保未来的读者意识到任何潜在的问题。未定义的行为意味着这可能会在 iOS 的未来版本中停止工作。
\n| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |