flo*_*_23 16 fullscreen orientation ios avplayer swift
我的应用程序是一个仅限肖像的应用程序,但我有一个视图控制器,它使用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)
}
Run Code Online (Sandbox Code Playgroud)
这就是我调用初始化我的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
})
})
}
}
Run Code Online (Sandbox Code Playgroud)
问题:当我打开播放器的全屏视图,然后更改为横向,然后单击"完成"以关闭全屏视图,我的应用程序保持在横向.但我想让它再次旋转成肖像.我怎样才能做到这一点?
而不是application(_:supportedInterfaceOrientationsForWindow:)尝试supportedInterfaceOrientations()在每个视图控制器上实现。例如:
override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
Run Code Online (Sandbox Code Playgroud)
这将确保视图控制器无法横向显示,因此当关闭视频播放器时,它将直接返回到纵向窗口。
更新Objective-C:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6334 次 |
| 最近记录: |