我的應用程序是一個只有肖像的應用程序,但我有一個視圖控制器使用AVPlayerViewController顯示實時流。iOS 8 - 在解除全屏後將方向改回到人像AVPlayerViewController
,以便對播放器的全屏視圖景觀我在AppDelegate.swift寫了這個方法:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
var orientation = UIInterfaceOrientationMask.Portrait
if let presentedController = window?.rootViewController?.presentedViewController? {
if presentedController.isKindOfClass(NSClassFromString("AVFullScreenViewController").self) {
orientation = .AllButUpsideDown
} else if let navController = presentedController as? UINavigationController {
if navController.topViewController.isKindOfClass(NSClassFromString("AVFullScreenViewController").self) {
orientation = .AllButUpsideDown
}
}
}
return Int(orientation.rawValue)
}
這是我如何調用初始化我AVPlayer:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showLiveStream" {
SVProgressHUD.show()
var queue: dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(queue, {
let streamURL = NSURL(string: liveStreamURL)
let playerItem = AVPlayerItem(URL: streamURL)
let player = AVPlayer(playerItem: playerItem)
dispatch_async(dispatch_get_main_queue(), {
SVProgressHUD.dismiss()
var playerViewController = segue.destinationViewController as AVPlayerViewController
playerViewController.player = player
})
})
}
}
問題是:當我打開播放器的全屏視圖時,然後切換到橫向,然後單擊「完成」以關閉全屏視圖,我的應用仍處於橫向模式。但我希望它再次旋轉到肖像。我怎樣才能做到這一點?
你是用'AVFullScreenViewController'類繼承'AVPlayerViewController'嗎? –
@LaurentRivard不,「AVFullScreenViewController」類是與「MPInlineVideoFullscreenViewController」運行時類相當的AVKit類。 –