Moja aplikacja jest aplikacją tylko portretową, ale mam jeden kontroler widoku, który wyświetla strumień na żywo, za pomocą kontrolera AVPlayerViewController.iOS 8 - zmiana orientacji z powrotem na portret przy wyłączaniu trybu pełnoekranowego AVPlayerViewController
Aby umożliwić krajobrazu dla widoku pełnoekranowym tego odtwarzacza Napisałem tę metodę w 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)
}
ten sposób wzywam zainicjować mój 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
})
})
}
}
Problem: gdy otwieram pełny ekran odtwarzacza, a następnie przełączam na krajobraz, a następnie klikam "Gotowe", aby zamknąć widok pełnoekranowy, moja aplikacja pozostanie w krajobrazie. Ale chcę, żeby znów się obracał do portretu. Jak mogę to zrobić?
Czy podklasy 'AVPlayerViewController' z klasy' AVFullScreenViewController'? –
@LaurentRivard Nie, klasa 'AVFullScreenViewController' jest odpowiednikiem AVKit klasy wykonawczej' MPInlineVideoFullscreenController'. –