【问题标题】:Orientation issue in ios 6ios 6中的方向问题
【发布时间】:2016-01-31 01:44:50
【问题描述】:

我正在使用通用应用程序,该应用程序在 ios 5 之前运行良好,但在 ios 6 中存在方向问题。我的应用程序仅处于纵向模式。问题是当我的 ipad 处于横向模式时,如果我启动我的应用程序,则方向不会更改为 protrait。因此,请帮助我编写一些代码,以便我在应用启动之前强制我的应用处于纵向模式,仅独立于设备的方向

【问题讨论】:

标签: iphone ios6


【解决方案1】:

首先我们必须在 Targets->Summary...中设置支持的方向...

在 iOS6.0 中 shouldAutorotateToInterfaceOrientation 方法已被弃用。因此,我们必须使用 shouldAutorotate 方法来代替此方法..

使用supportedInterfaceOrientations方法,如果我们想要所有方向,我们必须设置我们想要的方向,比如UIInterfaceOrientationMaskAll

【讨论】:

    【解决方案2】:

    这是因为 Apple 改变了管理 UIViewController 的方向的方式。在 iOS6 中,Oreintation 处理方式不同。在 iOS6 中容器(例如 UINavigationController)不会咨询其子级来确定它们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向设置为 iPad 惯用语的 UIInterfaceOrientationMaskAll 和 iPhone 惯用语的 UIInterfaceOrientationMaskAllButUpsideDown。所以设备的方向默认更改。

    所以需要执行一些步骤。

    1 - 从这里设置方向

    2 - 将此代码放在添加到 RootViewController 的 FirstViewController 中

      @implementation UINavigationController (RotationIn_IOS6)
       //Here UINavigationController is the RootViewController added To the Window
    
     -(BOOL)shouldAutorotate
    {
    return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
     -(NSUInteger)supportedInterfaceOrientations
    {
       return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
     - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
         return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }
    
    @end
    

    ** 把下面的方法放到ViewController中,IOS6中引入了Allow Oreintation Change**

      - (BOOL)shouldAutorotate
     {
    
       return NO;
    
      }
    
    /*Return the Number of Oreintation going to supported in device*/
    
     - (NSUInteger)supportedInterfaceOrientations
      {
    return  (UIInterfaceOrientationMaskPortrait |     UIInterfaceOrientationMaskPortraitUpsideDown );
    
     }
    
     // Returns interface orientation masks.
    
      - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
      {
          return  (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown      ) ;
    
     }
    

    【讨论】:

      【解决方案3】:

      在您的ViewController.m 中,您必须定义您支持的方向。在 IOS 6 中,这是处理支持的方向的方法。

      - (NSUInteger)supportedInterfaceOrientations{
          return UIInterfaceOrientationMaskAll;
      }
      

      UIInterfaceOrientationMaskAll 表示它将支持view 的所有方向。

      还可以阅读 Apple 文档 - Doc about Orientation

      【讨论】:

        猜你喜欢
        • 2012-09-30
        • 1970-01-01
        • 2012-09-12
        • 2013-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-24
        相关资源
        最近更新 更多