如何在iPhone应用程序上仅支持纵向模式

如何在iPhone应用程序上仅支持纵向模式,iphone,objective-c,xcode,autorotate,device-orientation,Iphone,Objective C,Xcode,Autorotate,Device Orientation,我正在开发的iPhone应用程序有一个奇怪的问题。我希望我的应用程序只支持肖像模式,但由于某些原因我无法做到(设备和模拟器) 为了只支持纵向模式,我做了如下操作: 在Xcode的目标摘要部分,我只选择了肖像 所有my ViewController实现的应为AutoRotateTointerFaceOrientation 但正如我所说,它不会工作,奇怪的结果是,应用程序支持所有方向(纵向、倒置、左横向、右横向)。 有什么想法吗 这就是我如何实现应自动旋转指向面定位的方法 - (BOOL)sho

我正在开发的iPhone应用程序有一个奇怪的问题。我希望我的应用程序只支持肖像模式,但由于某些原因我无法做到(设备和模拟器)

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

  • 在Xcode的目标摘要部分,我只选择了肖像
  • 所有my ViewController实现的
    应为AutoRotateTointerFaceOrientation
但正如我所说,它不会工作,奇怪的结果是,应用程序支持所有方向(纵向、倒置、左横向、右横向)。
有什么想法吗

这就是我如何实现
应自动旋转指向面定位的方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     // Return YES for supported orientations
     NSLog(@"Checking orientation %d", interfaceOrientation);
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
我刚才注意到当我旋转手机时,我收到以下信息:

“不推荐使用两阶段旋转动画。此应用程序应 使用更平滑的单阶段动画。”


这意味着什么?

在目标摘要上选择仅纵向。

检查您的plist并确保那里的键设置正确。

转到info.plist文件。右键单击“将其作为源代码打开”。看看这条线。对我来说,iPad是这样的:

  <key>UISupportedInterfaceOrientations~ipad</key>
ui支持的界面方向~ipad
删除所有其他方向并保留唯一需要的方向..如下所示:

    <array>

    <string> UIInterfaceOrientationPortrait </string>

</array>

UIInterfaceOrientationPortrait

屏幕上可以有多个ViewController。
UIAbbarController
本身就是一个
UIViewController
,如果选择,它只会将
shouldAutorotateToInterfaceOrientation:
请求传递给中的ViewController。默认实现会执行此操作,但如果将其子类化,则XCode生成的代码(从iOS 5.1开始)不会执行此操作。

请尝试删除shouldAutorotateToInterfaceOrientation方法并保持目标设置正确。请尝试我的答案。可能会有帮助。请尝试添加
NSLog(@“检查方向%d”,interfaceOrientation)到您的
shouldAutorotateToInterfaceOrientation
方法。旋转模拟器或设备时是否调用了其中任何一个?谢谢您的帮助,是的,日志打印“检查方向1”。但是我注意到了其他的事情,请检查我的更新question@Eyal:附加控制台消息可能意味着您的代码实现了旧的、已弃用的以及类似的WillAnimateFirsthalfoFrotationInterfaceOrientation:duration:和WillAnimateSecondHalf RotationFromInterfaceOrientation:duration:。您可能不需要这些方法。@Eyal:InterfaceOrientation1是
UIInterfaceOrientationGrait
,这正是您所期望的。如果这真的发生在你旋转到横向时,这比以往任何时候都更奇怪:设备返回YES,因为它认为它正在旋转到纵向。你能发布一个完整的
shouldAutorotateToInterfaceOrientation
方法吗?