【问题标题】:return back from B VIewcontroller(Fixed Portrait), to A , A is not rotating to landscape mode automatically(Device is in Landscape Mode)从 B VIewcontroller(Fixed Portrait) 返回到 A,A 不会自动旋转到横向模式(设备处于横向模式)
【发布时间】:2013-12-26 07:06:11
【问题描述】:

我将设备置于横向模式并移至仅支持纵向模式的第二个视图控制器。从第二个视图控制器返回时(支持所有方向),第一个视图控制器不会自动旋转到横向模式。

如果我做了下面的代码,那么它在 IOS6 中的工作。但不适用于 IOS7。

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    [UIViewController attemptRotationToDeviceOrientation];
}

在 IOS7 中 viewController 正在旋转,但状态栏没有旋转

【问题讨论】:

    标签: ios iphone ios7 uiinterfaceorientation


    【解决方案1】:

    在 VC A 中实现以下内容:

    -(BOOL)shouldAutorotate
    {
        return NO;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationLandscapeRight;
    }
    

    【讨论】:

      【解决方案2】:

      AMayes 提出的解决方案并不完全正确。

      UIViewController 文档声明如下:

      通常,系统仅在根视图上调用此方法 窗口的控制器或视图控制器,用于填充 整个屏幕;子视图控制器使用窗口的一部分 由他们的父视图控制器为他们提供,不再 直接参与有关支持哪些轮换的决策。

      因此,将以下代码放在 UINavigationController 子类中:

      -(NSUInteger)supportedInterfaceOrientations
      {
          return UIInterfaceOrientationMaskLandscape;
      }
      
      - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
      {
          return UIInterfaceOrientationLandscapeRight;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-01
        • 1970-01-01
        • 2013-09-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多