【问题标题】:I can't rotate my portrait app for a single screen我无法为单个屏幕旋转纵向应用程序
【发布时间】:2018-02-15 07:18:41
【问题描述】:

这是我故事板的一部分,我尝试过,但无法处理。

我在 navigationController 中尝试过,但没有成功。你有什么建议吗?

override var shouldAutorotate : Bool {
    if self.topViewController != nil{
        return self.topViewController!.shouldAutorotate
    }else{
        return  super.shouldAutorotate
    }
}

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
    if self.topViewController != nil{
        return self.topViewController!.supportedInterfaceOrientations
    }else{
        return  super.supportedInterfaceOrientations
    }
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
    if self.topViewController != nil{
        return self.topViewController!.preferredInterfaceOrientationForPresentation
    }else{
        return  super.preferredInterfaceOrientationForPresentation
    }
}

override var preferredStatusBarStyle : UIStatusBarStyle {
    return self.topViewController!.preferredStatusBarStyle
}

【问题讨论】:

  • 以上代码必须在视图控制器中使用
  • @Vinodh 我直接在 ViewController 中尝试过,但我抛出了一个错误,*** 由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“支持的方向与应用程序没有共同的方向,并且 [ EZPlayer.EZPlayerFullScreenViewController shouldAutorotate] 正在返回 YES'

标签: ios swift xcode uinavigationcontroller screen-rotation


【解决方案1】:

您可以将此应用程序生命周期方法 supportedInterfaceOrientationsFor 添加到您的应用程序委托类中,以根据您的要求支持各种方向。

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

    if self.window?.rootViewController != nil {

        if self.window!.rootViewController! is UITabBarController {

            if self.window?.rootViewController?.childViewControllers.last is UINavigationController {

                if self.window?.rootViewController?.childViewControllers.last?.childViewControllers.last is YourViewController {
                    return UIInterfaceOrientationMask.all;
                } else {
                    return UIInterfaceOrientationMask.portrait;
                }

            } else {
                if self.window!.rootViewController?.childViewControllers.last is YourViewController {
                    return UIInterfaceOrientationMask.all;
                } else {
                    return UIInterfaceOrientationMask.portrait;
                }
            }                       
        }
    }
}

【讨论】:

  • @GreatCornholio 您觉得我的解决方案对您有帮助吗?
  • 不,先生,没有工作并崩溃:/ 崩溃:对多个未捕获的异常进行保释:支持的方向与应用程序没有共同的方向,[EZPlayer.EZPlayerFloatContainerRootViewController shouldAutorotate] is returning YES 2018-02-18 15:07:34.823482+0300 DeMarke[1070:1109572] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [EZPlayer.EZPlayerFloatContainerRootViewController shouldAutorotate] is returning YES'
  • 我的 ViewController 只包含这个旋转代码; override var shouldAutorotate : Bool { return true }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多