【问题标题】:how to set portrait mode only in our iphone app?如何仅在我们的 iPhone 应用程序中设置人像模式?
【发布时间】:2012-08-20 07:44:59
【问题描述】:

我在我的 iPhone 应用程序中遇到了一个奇怪的问题。我希望我的应用仅支持纵向模式,但由于某种原因我无法做到(设备和模拟器)。

为了只支持纵向模式,我做了如下操作:

In the TARGET summary section on Xcode, I chose only portrait.
All my ViewControllers implements shouldAutorotateToInterfaceOrientation

但正如我所说,它不起作用,奇怪的结果是应用程序支持所有方向(纵向、倒置、横向左侧、横向右侧)。 有什么想法吗?

这就是我实现 shouldAutorotateToInterfaceOrientation 的方式

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     // Return YES for supported orientations
     NSLog(@"Checking orientation %d", interfaceOrientation);
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

非常感谢。

【问题讨论】:

    标签: iphone orientation portrait


    【解决方案1】:

    在应用的 info.plist 文件中设置键“支持的界面方向 (iPhone)”与您想要的方向。

    这里我只使用横向,你可以使用纵向。

    【讨论】:

    • 如果我的回答对您有帮助,请点击接受检查和向上箭头,这也将帮助您快速回答问题。
    【解决方案2】:

    试试这个先生,

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    // Return YES for supported orientations
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    

    希望对您有所帮助。 谢谢:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 2011-10-04
      • 2012-06-01
      • 1970-01-01
      • 2012-04-23
      • 2014-11-23
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多