ios - 无法获得 supportedInterfaceOrientationsForWindow 以使用 Swift 1.2

标签 ios iphone swift mpmovieplayercontroller

嘿 Stackoverflow 成员(member), 也许你可以帮助我解决我的问题。

问题是我想将所有 UIViewController 的方向锁定为“纵向”,但如果 MoviePlayer 出现,它应该切换到横向模式,如果电影播放器​​消失则返回。

在 Swift 1.2 之前我使用:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> UIInterfaceOrientationMask {
//If the video is being presented, let the user change orientation, otherwise don't.
if let presentedViewController = window.rootViewController?.presentedViewController? {
    if (presentedViewController.isKindOfClass(MPMoviePlayerViewController) && !presentedViewController.isBeingDismissed()) {
        return .AllButUpsideDown
    }
}
return .Portrait
}

在 Swift 1.2 中,一些事情发生了变化,所以我得到了以下代码:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
    //If the video is being presented, let the user change orientation, otherwise don't.
    if let presentedViewController = window?.rootViewController?.presentedViewController {
        if (presentedViewController.isKindOfClass(MPMoviePlayerViewController) && !presentedViewController.isBeingDismissed()) {
            return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
        }
    }
    return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}

但是我的代码不起作用,电影播放器​​ (XCDYoutube) 被锁定在纵向模式。设备方向设置应该没问题!

预先感谢您的帮助!

最佳答案

我的逻辑与您的类似,但最终返回了对所有方向的支持。

在 appdelegate 中返回 UIInterfaceOrientationMaskAll。

根据您拥有的 View Controller 数量 - 您可能想要创建 UIViewController 的抽象子类并仅返回对纵向的支持/然后修改您的 youtube View Controller 以支持横向。

  • (NSUInteger)supportedInterfaceOrientations { 返回 UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;

关于ios - 无法获得 supportedInterfaceOrientationsForWindow 以使用 Swift 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29676735/

相关文章:

iphone - 为 iPhone 制作可点击的 HTML div

swift - 如何在绑定(bind)到核心数据的 NSPopUpButton 中预选一个项目?

ios - Json 数据未显示在 tableView 上

ios - 声明选择器 presentviewcontroller

ios - 在线和离线管理 iPhone 应用程序

ios - Ionic CLI 错误 - 错误 : Cannot read property 'indexOf' of null on terminal

ios - 苹果开发者账号 :- how to change the "agent name"?

iphone - 如何制作顶部带有文本字段的键盘?

ios - Alamofire.requestObject 自定义案例未调用

ios - 翻转 NSScrollView 问题