【问题标题】:iPhone/iPad App OrientationiPhone/iPad 应用方向
【发布时间】:2012-09-14 10:39:43
【问题描述】:

我的应用程序的 iPhone 版本支持 UIDeviceOrientationPortraitUpsideDownUIDeviceOrientationPortrait,但 iPad 版本支持所有方向。

在我的视图控制器中,我有这个:

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

我的 Info.plist 文件有这个:

问题是当我将应用程序构建到我的 iPod 时,应用程序不会颠倒过来。 iPad 将支持所有方向。

我已经尝试将shouldAutorotateToInterfaceOrientation 一起删除,并且我已经尝试了以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation = UIDeviceOrientationLandscapeLeft) && (interfaceOrientation = UIDeviceOrientationLandscapeRight) && (interfaceOrientation = UIDeviceOrientationPortraitUpsideDown) && (interfaceOrientation = UIDeviceOrientationPortrait);
}

但由于某种原因,颠倒是行不通的!有没有其他解决方案?

编辑:使用 Xcode 4.5 iOS6

【问题讨论】:

    标签: iphone xcode orientation


    【解决方案1】:

    想通了,iOS6 SDK 使用shouldAutorotate 所以这是我的新代码:

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
    }
    
    -(BOOL)shouldAutorotate {
         return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAll;
    }
    

    【讨论】:

    • 那么你必须同时拥有 -(BOOL)shouldAutorotate 吗?还是只需要 IOS6 SDK 的那个?
    • 我两个都用了,因为iOS
    • 好吧,酷。请让我了解最新情况,因为看看你是只需要保留一个还是必须保留两个会很有趣
    • 关于 iPhone 和 iPad 的区别,我在 info.plist 中定义了这些
    • 大家好。我也尝试使用它,但它对我不起作用。请帮助我。我现在被困住了。谢谢。
    【解决方案2】:

    如果我理解正确,您希望 iPad 支持所有方向,而您希望 iPhone 仅支持倒置和纵向旋转。试试这个作为解决方案。 (这是一种比你上面所做的更简单的方法)

       -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
              return YES;
         }
    
        else {
                return UIInterfaceOrientationIsPortrait(interfaceOrientation);
            }
     }
    

    我还想补充一点,您必须将其添加到每个单独的视图控制器中,以便它也可以旋转到另一个视图。

    例如,假设我有 viewcontroller_1 和 viewcontroller_2,我必须进入控制器的两个 .m 文件并添加以下代码。如果您不这样做,它可能不会针对其中一个视图旋转。

    【讨论】:

    • 感谢您的回复,我用我自己的答案中发布的代码解决了它,检查一下。
    【解决方案3】:
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    

    此方法在IOS 6已弃用,因此您可以使用以下方法代替它。

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }
    

    根据你的返回方向。

    【讨论】:

      【解决方案4】:

      另一种支持方向的方法是继承 UINavigationController 并在其中添加方向代码

      //IOS 5
      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
          return YES;
      }
      //IOS 6
      - (BOOL)shouldAutorotate {
          return YES;
      }
      - (NSUInteger)supportedInterfaceOrientations {
          return UIInterfaceOrientationMaskAll;
      }
      

      这对我有用,使用故事板

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-08
        • 1970-01-01
        • 2011-10-06
        • 1970-01-01
        相关资源
        最近更新 更多