• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 仅允许系统 AVPlayerViewController 的全屏横向

[复制链接]
菜鸟教程小白 发表于 2022-12-12 22:47:53 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个应用程序,它使用 UISplitViewController 在详细 View Controller 中加载网页,该 Controller 具有 WKWebView 属性。一些 URL 是嵌入的 YouTube 视频的链接,一些是 .mp4 文件的直接链接。无论哪种方式,视频文件都会自动加载(在点击 YouTube 视频之后)到全屏系统播放器中,我假设它是一个 AVPlayerViewController。我看过几篇关于通过实现 supportedInterfaceOrientations 子类化 AVPlayerViewController 以允许旋转的帖子,以及其他建议检查 UIWindow 类的帖子的 rootViewController presentedViewControllerapplication:supportedInterfaceOrientationsForWindow: 或检查 AppDelegate 上设置的变量 AVPlayerViewController 已提出,但这些解决方案都没有为我工作,因为我没有创建或呈现我自己的 AVPlayerViewController 实例,所以我不知道如何允许播放这些视频时旋转为横向。

有什么方法可以让我知道系统何时以全屏模式播放视频,以便允许旋转?

以下是我已经看过的一些帖子的链接:

MPMoviePlayerViewController | Allow landscape mode

Only ONE VIEW landscape mode



Best Answer-推荐答案


我希望你仍然需要一个答案。我在 Swift 中找到了解决方案,但它可以在 Objective C 中简单地转换。我发现,当使用 WKWebView(也可能是 UIWebView)时,全屏视频会在新的 UIWindow 中呈现(至少在 iOS 10 上)。该窗口有空白的 UIViewController 并在其上显示 AVFullScreenViewController

所以,在你的 AppDelegate 中你应该像这样实现 application:supportedInterfaceOrientationsForWindow:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if window != self.window, let pvc = window?.rootViewController?.presentedViewController, "\(type(of: pvc))" == "AVFullScreenViewController" {
        return pvc.isBeingDismissed ? .portrait : .all
    }
    return .portrait
}

虽然 AVFullScreenViewController 是私有(private) API 类,但您可以保护自己并将 "AVFullScreenViewController" 替换为 String(format: "AV%@ViewController", "FullScreen ")

祝你好运!

关于ios - 仅允许系统 AVPlayerViewController 的全屏横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40555385/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap