gpt4 book ai didi

iOS 8 - 在关闭全屏 AVPlayerViewController 时将方向更改回纵向

转载 作者:IT王子 更新时间:2023-10-29 05:19:53 28 4
gpt4 key购买 nike

我的应用程序是一个纵向应用程序,但我有一个 View Controller 正在使用 AVPlayerViewController 显示实时流。

为了允许该播放器的全屏 View 横向显示,我在 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
})
})
}
}

问题:当我打开播放器的全屏 View ,然后更改为横向 View ,然后单击“完成”关闭全屏 View 时,我的应用程序保持横向。但我希望它再次旋转为纵向。我该怎么做?

最佳答案

与其实现application(_:supportedInterfaceOrientationsForWindow:),不如尝试在每个 View Controller 上实现supportedInterfaceOrientations()。例如:

override func supportedInterfaceOrientations() -> Int {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}

这将确保 View Controller 不能横向显示,因此当关闭视频播放器时,它会直接回到纵向窗口。

更新 Objective-C:

- (NSUInteger)supportedInterfaceOrientations { 
return UIInterfaceOrientationMaskPortrait;
}

关于iOS 8 - 在关闭全屏 AVPlayerViewController 时将方向更改回纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27595317/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com