如何在 Xcode 4.5 中创建 IOS 5.1 应用程序

Posted

技术标签:

【中文标题】如何在 Xcode 4.5 中创建 IOS 5.1 应用程序【英文标题】:How to create IOS 5.1 apps in Xcode 4.5 【发布时间】:2012-11-20 17:10:46 【问题描述】:

我在 Xcode 4.5 上为 ios 5 创建 Ipad 应用程序时遇到横向问题 我看到的相关问题很少,但大多数都与我的情况相反。

我不使用Bool autorotate 之类的任何代码,我只是在界面生成器上选择横向。取消选择使用自动布局。

当我创建应用程序时,我在项目文件夹(蓝色图标)上选择 IOS Deployment Target 5.1

Build settings is architecture Base Sdk is IOS 6

故事板导航控制器设置为横向,界面文档设置为5.1

在 IOS 6 模拟器环境中运行良好:

但在 IOS 5.1 Simulator 环境中不起作用且迷失方向

我错过了什么?我怎样才能使这适用于 5.1 和 6 版本?

编辑=====

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

    if (interfaceOrientation==UIInterfaceOrientationLandscapeRight)
        return YES;

    return NO;

上面的代码也不起作用。它仍然是一样的。

【问题讨论】:

【参考方案1】:

您应该在视图控制器上覆盖 shouldAutorotateToInterfaceOrientation: 并为您想要的方向返回 YES,例如

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;

【讨论】:

编辑过的问题我实际上在发布问题之前尝试过,但仍然无法正常工作 您将支持的界面方向设置为仅横向,对吧? 在故事板上 -> 模拟指标 -> 方向设置为横向 好的,现在在导航控制器的根控制器中覆盖方法使其工作。【参考方案2】:

在 IOS 6.0 之前,您必须在项目的所有 ViewController 上覆盖此方法。在 IOS 6 中,Apple 终于纠正了这种行为

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

【讨论】:

【参考方案3】:

使用以下代码更新所有视图控制器。

适用于 Simulator 5.0 及更高版本。

-(NSUInteger)supportedInterfaceOrientations
    return UIInterfaceOrientationMaskAll;


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

【讨论】:

以上是关于如何在 Xcode 4.5 中创建 IOS 5.1 应用程序的主要内容,如果未能解决你的问题,请参考以下文章