Swift,添加chromecast迷你控制器后应该没有调用

时间:2016-11-21 15:51:50

标签: ios swift chromecast

我正在快速制作视频应用程序,通常应用程序处于纵向模式,但当用户进入播放器视图时,他可以旋转设备,我用shouldAutorotate控制它,当我不想要应用程序时旋转我返回false,反之亦然。

我无法取消选中设备方向标记,因为我需要旋转应用程序。

问题是,当我添加chromcast的迷你控制器时,我必须像这样设置它:

let appStoryBoard = UIStoryboard.init(name: "Main", bundle: nil)

let tmpNavigationController = appStoryBoard.instantiateViewController(withIdentifier: "NavigationMain")

let castContainerVC: GCKUICastContainerViewController = GCKCastContext.sharedInstance().createCastContainerController(for: tmpNavigationController)

castContainerVC.miniMediaControlsItemEnabled = true

self.window?.rootViewController = castContainerVC

但是一旦我设置了rootViewController = castContainerVc,我的应用程序就会停止调用shouldAutorotate方法并且应用程序随处可以自由旋转,任何解决方法?

1 个答案:

答案 0 :(得分:1)

GCKUICastContainerViewController rootViewController 时,您可以做些什么来管理旋转状态:

  

扩展 GCKUICastContainerViewController 并覆盖您需要的内容

Swift 2.x

extension GCKUICastContainerViewController{

override public func shouldAutorotate() -> Bool {
    //Do what ever you need here
    return true
}

override public func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    //Do what ever you need here
    return .All
}

override public func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    //Do what ever you need here
    return .All
}}

Swift 3.x

extension GCKUICastContainerViewController{

override open var shouldAutorotate:Bool {
    //Do what ever you need here
    return true
}

override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    //Do what ever you need here
    return .all
}

override open var preferredInterfaceOrientationForPresentation:UIInterfaceOrientation {
    //Do what ever you need here
    return .all
}}