presentsViewController更改呈现视图控制器的方向,打破布局

时间:2015-08-05 23:42:52

标签: ios swift autolayout uiinterfaceorientation

我有一个显示A的ViewController MPMoviePlayerViewController。我想强制视频播放器横向显示,所以我使用它:

在AppDelegate中,supportedInterfaceOrientationsForWindow

if let viewController = self.window!.rootViewController?.presentedViewController {
            if let playbackController = viewController as? MPMoviePlayerViewController {
                return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue) | Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
            }
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }

在我的视频播放器子类中,我设置了支持的方向:

override func supportedInterfaceOrientations() -> Int {
        return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue) | Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
    }

但是,当横向关闭视频播放器时,视图控制器A会陷入困境。如何阻止View Controller A切换到横向,并将其保持为纵向?

1 个答案:

答案 0 :(得分:0)

Just add

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

to every view controller that needs it and avoid AppDelegate based orientation support.