解雇模态视图控制器时如何保持呈现视图控制器的方向? [英] How to maintain presenting view controller's orientation when dismissing modal view controller?

查看:83
本文介绍了解雇模态视图控制器时如何保持呈现视图控制器的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个应用程序,我正在努力,我需要所有的视图控制器,但一个是肖像。
一个特殊的单视图控制器我需要它才能旋转到手机的任何方向。

I have this app I am working on and I need ALL my view controllers but one to be in portrait. The single one view controller that is special I need it to be able to rotate to whatever orientation the phone is in.

为此,我以模态方式呈现它(没有嵌入在NavigationController中)

To do that I present it modally (not embedded in a NavigationController)

所以(例如)我的结构是这样的:

So (for example) my structure is like this:


  • 窗口 - 人像

    • 根视图控制器(UINavigationController - Portrait)

      • 主视图控制器(UIViewController - 肖像)

        • 详情视图控制器(UIViewController - Portrait)




        • 模态视图控制器(UIVIewController - 全部)

        • window - Portrait
          • root view controller (UINavigationController - Portrait)
            • home view controller (UIViewController - Portrait)
              • details view controller (UIViewController - Portrait)
              • .
              • .
              • .
              • modal view controller (UIVIewController - All)

              现在,当我在横向位置解除模态视图控制器时,我的父视图控制器也会旋转,即使它不支持该方向。

              Now when ever I dismiss my modal view controller in a landscape position my parent view controller is ALSO rotated even though it doesn't support that orientation.

              全部<$应用程序中的c $ c> UIViewControllers 和 UINavigaionControllers 继承了实现这些方法的相同通用类:

              All UIViewControllers and UINavigaionControllers in the app inherit from the same general classes which have these methods implemented:

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

              我的模态视图控制器再次覆盖此方法,它看起来像这样:

              My modal view controller overrides this method once again and it looks like this:

              override func supportedInterfaceOrientations() -> Int
              {
                  return Int(UIInterfaceOrientationMask.All.toRaw())
              }
              

              更新1

              看起来这只发生在iOS8 Beta上。
              有人知道视图控制器的轮换是否有变化,或者这只是测试版中的错误?

              It looks like this is happening only on iOS8 Beta. Does someone know if there is something that changed regarding view controller's rotation or is this just a bug in the beta?

              推荐答案

              - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
              {
              if ([self.window.rootViewController.presentedViewController isKindOfClass: [SecondViewController class]])
              {
                  SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
              
                  if (secondController.isPresented)
                      return UIInterfaceOrientationMaskAll;
                  else return UIInterfaceOrientationMaskPortrait;
              }
              else return UIInterfaceOrientationMaskPortrait;
              }
              

              对于Swift

              func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
              
                  if self.window?.rootViewController?.presentedViewController? is SecondViewController {
              
                      let secondController = self.window!.rootViewController.presentedViewController as SecondViewController
              
                      if secondController.isPresented {
                          return Int(UIInterfaceOrientationMask.All.toRaw());
                      } else {
                          return Int(UIInterfaceOrientationMask.Portrait.toRaw());
                      }
                  } else {
                      return Int(UIInterfaceOrientationMask.Portrait.toRaw());
                  }
              
              }
              

              有关详情,请查看 link

              这篇关于解雇模态视图控制器时如何保持呈现视图控制器的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆