【问题标题】:orientation issue in IOS 5.1?IOS 5.1 中的方向问题?
【发布时间】:2013-10-22 14:47:37
【问题描述】:

我已经在 IOS 6.0 中实现了带有方向支持的示例代码,它可以正常工作,但是如果我在 ipad 1 (IOS 5.1) 中运行,相同的应用程序不支持方向。我知道 IOS 6.0 不推荐使用 iOS 5.1 中的某些方法如何解决这个问题?

【问题讨论】:

    标签: ios uiinterfaceorientation


    【解决方案1】:

    您需要在视图控制器中实现旧的旋转方法以支持 iOS 5 或更低版本的旋转。

    是的,这些方法已被弃用,但旧版本的 iOS 仍然需要这些方法。

    【讨论】:

    • 感谢@rckoenes 的回复,所以我需要两种方法来支持 IOS 6 和 5 中的相同应用程序,对吗?
    【解决方案2】:

    对于 iOS 6+,请使用这些方法

    - (NSUInteger)supportedInterfaceOrientations {
    
        return UIInterfaceOrientationMaskPortrait;
    }
    
    - (BOOL)shouldAutorotate {
    
        return UIInterfaceOrientationMaskPortrait;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
        return UIInterfaceOrientationPortrait;
    }
    

    对于 iOS 5.0 和所有以前的使用这个

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {  
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

    【讨论】:

    • 感谢@JayD,但如果在 IOS 6.0 中开发应用程序并希望支持像 5.0 这样的低版本,我需要在我的代码中调用这两种方法吗?
    • 你好@JayD请澄清我的疑问
    • 如果我在 IOS 6.0 中创建应用程序并希望同时支持这两个版本,那么我需要在 IOS 6.0 和 5.0 中调用这两种方法是否正确?
    【解决方案3】:

    在 .m 文件中使用以下代码。

    // Override to allow orientations other than the default portrait orientation.
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
    if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)  {
               return NO;
    }
    else {
        return YES;
    }
    
    }
    

    这适用于 iOS 5.1、6.1.3 和 7.0.2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 2013-10-14
      • 2015-11-03
      • 2013-11-17
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多