仅允许系统AVPlayerViewController

时间:2016-11-11 20:03:31

标签: ios objective-c rotation avplayer

我有一个应用程序使用UISplitViewController在详细信息视图控制器中加载网页,该网页具有WKWebView属性。有些网址是嵌入式YouTube视频的链接,有些是直接链接到.mp4文件。无论哪种方式,视频文件都会自动加载(在点击YouTube视频之后)到全屏系统播放器中,我假设是AVPlayerViewController。我已经看过几篇关于通过实施AVPlayerViewController进行子类化supportedInterfaceOrientations以允许轮换的帖子,以及其他建议检查UIWindow' {{{在rootViewController中{}} presentedViewController或检查application: supportedInterfaceOrientationsForWindow:上显示AppDelegate时的变量,但这些解决方案都没有对我有用,因为我&# 39;我没有创建或展示我自己的AVPlayerViewController实例,所以我不确定在播放这些视频时如何让旋转成为横向。

当系统以全屏模式播放视频时,有什么办法可以判断,我可以允许旋转吗?

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

MPMoviePlayerViewController | Allow landscape mode

Only ONE VIEW landscape mode

1 个答案:

答案 0 :(得分:2)

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

所以,在你的AppDelegate中你应该像这样实现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"

虽然 AVFullScreenViewController 是私有API类,但您可以保护自己并将String(format: "AV%@ViewController", "FullScreen")替换为 app.controller("blankCtrl", ['$scope', '$http', '$parse', function($scope, $http, $parse) { $scope.login = function() { $scope.spice = 'tooo'; alert("hiii"); $.ajax({ url : "http://edudux.com/manage/index.php?/api/login", dataType:"json", success:function(data) { alert("mobile:"+data.mobile+"\npassword:"+data.password); } }); } }]);

祝你好运!