仅适用于视频的横向模式

时间:2016-03-14 19:54:01

标签: ios swift cocoa-touch avfoundation

我的应用程序仅支持纵向模式,但对于我在全屏幕上从UIWebView播放的视频也应该支持横向模式。我搜索了很多并找到了一些答案,例如通过添加我不做的通知,因为有很多通知其他的东西和我发现工作的第二个是这段代码:

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {

    var classesToCheckFor = [AnyClass]()

    if let ios7Class = NSClassFromString("MPInlineVideoFullscreenViewController") {
        classesToCheckFor.append(ios7Class)
    }

    if let ios8Class = NSClassFromString("AVFullScreenViewController") {
        classesToCheckFor.append(ios8Class)
    }

    for classToCheckFor in classesToCheckFor {
        if (self.window?.rootViewController?.presentedViewController?.isKindOfClass(classToCheckFor) != nil) {
            return .AllButUpsideDown
        }
    }

    return .Portrait
}

它在iOS 9中运行良好,但在iOS 8中运行不正常。任何人都知道如何在iOS 8中执行此操作。

或者还有其他方法可以做到这一点吗?

1 个答案:

答案 0 :(得分:0)

我得到解决方案只需删除关键字self,它在ios 8和ios 9中都运行良好。更改代码

    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {

    var classesToCheckFor = [AnyClass]()

    if let ios7Class = NSClassFromString("MPInlineVideoFullscreenViewController") {
        classesToCheckFor.append(ios7Class)
    }

    if let ios8Class = NSClassFromString("AVFullScreenViewController") {
        classesToCheckFor.append(ios8Class)
    }

    for classToCheckFor in classesToCheckFor {
        if (window?.rootViewController?.presentedViewController?.isKindOfClass(classToCheckFor) != nil) {
            return .AllButUpsideDown
        }
    }

    return .Portrait
}