【问题标题】:Locking the Landscape Mode in iPad在 iPad 中锁定横向模式
【发布时间】:2013-05-07 03:31:40
【问题描述】:

我正在使用此代码为我的 iOS 应用程序锁定横向模式。

#pragma mark Orientation handling

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

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

它在 iPhone 上运行良好,但在 iPad 上运行不正常。它不会锁定横向模式。

需要一些指导。

【问题讨论】:

  • 您也可以在 Xcode 的摘要选项卡中为您的应用设置方向。
  • 我的一些屏幕需要它们处于横向模式。这就是为什么我以编程方式进行...
  • 你的结果是什么?它是自动旋转的吗?
  • iPad版自动旋转...
  • 在 shouldAutorotateToInterfaceOrientation 上放置断点。开火了吗?

标签: ios ipad


【解决方案1】:

此代码不正确:

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

UIInterfaceOrientation 不是UIInterfaceOrientationMask。试试这样的:

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

话虽如此,如果您试图将应用程序锁定在 横向 模式,这里还有多个其他问题 - 例如,您的 supportedInterfaceOrientations 仅列出纵向模式,而不是横向模式!

【讨论】:

    【解决方案2】:

    理想情况下,只需按照评论所述将其设置在摘要选项卡中即可。如果您真的想在代码中执行此操作,这仅适用于您在 AppDelegate 类中设置为 rootViewController 的任何内容。

    【讨论】:

      【解决方案3】:

      在 iOS 6 中我使用:

      - (NSUInteger)supportedInterfaceOrientations {
          return UIInterfaceOrientationMaskLandscape;
      }
      

      如果您有 NavigationController,则可以将方法添加到 Category。

      【讨论】:

        【解决方案4】:

        我用:

        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
        {
            return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
                   interfaceOrientation == UIInterfaceOrientationLandscapeRight;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-04-11
          • 1970-01-01
          • 2012-01-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多