2016-11-11 21 views
2

我有使用UISplitViewController加載的詳細信息視圖控制器,具有WKWebView屬性網頁的應用程序。其中一些網址是指向嵌入式YouTube視頻的鏈接,另一些則是直接鏈接到.mp4文件。無論哪種方式,視頻文件會自動加載到全屏播放系統,我認爲是一個AVPlayerViewController(攻爲YouTube視頻後)。我已經看到了關於繼承AVPlayerViewController允許通過實施supportedInterfaceOrientations旋轉幾個職位,和其他職位,其中建議無論是檢查類的UIWindowrootViewControllerpresentedViewControllerapplication: supportedInterfaceOrientationsForWindow:或檢查的AppDelegate所設定的變量時,AVPlayerViewController提出的,但這些解決方案都爲我工作,因爲我沒有創建或呈現AVPlayerViewController我自己的例子,所以我不知道如何讓旋轉到橫向時,這些視頻在播放的。允許全屏橫向僅對系統AVPlayerViewController

有沒有一種方式,當系統正在播放在全屏模式下的視頻,我可以告訴,這樣我就可以讓旋轉?

這裏是鏈接到一些我已經看到了帖子:

MPMoviePlayerViewController | Allow landscape mode

Only ONE VIEW landscape mode

回答

1

我希望你仍然需要一個答案。我已經發現了斯威夫特的解決方案,但它在客觀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是私有的API類,ü可以保護urself與String(format: "AV%@ViewController", "FullScreen")

好運更換"AVFullScreenViewController"

相關問題