0

我知道:默认情况下,应用程序和视图控制器支持的界面方向设置为 iPad 惯用语的 UIInterfaceOrientationMaskAll 和 iPhone 惯用语的 UIInterfaceOrientationMaskAllButUpsideDown 。因此,当我使用单视图应用程序模板创建一个新项目时,为了在 iPhone 中执行所有方向,我在 ViewController.m 中添加了以下两个方法。它工作!

- (NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotate
{
    return YES;
}

然后我更改了 AppDelegate.m 下面方法中的一些代码,将应用程序的根视图从 UIViewController 更改为 UINavigationController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
    }
    if(myNavigationController == nil)
        myNavigationController = [[UINavigationController alloc]initWithRootViewController:self.viewController];

    self.window.rootViewController = self.myNavigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

之后,我无法在 iPhone iOS6 模拟器中处理 UIInterfaceOrientationPortraitUpsideDown 。我该如何解决?我尝试在较旧的主题中搜索一些代码,但仍然无法正常工作。

4

1 回答 1

0

myNavigationController财产吗?您将其引用为myNavigationControllerand self.myNAvigationController。似乎不一致,特别是因为您初始化引用 ivar 的对象,然后使用属性设置窗口的 rootViewController。

另外,你应该澄清你的问题。我想你是在问如何让 iPhone 自动旋转到倒立的肖像。答案是:不要。iPhone 不支持水平旋转锁定(与 iPad 不同),并且违反了设计准则。

话虽这么说:您可能想要检查您的所有 viewController 是否实现了旋转代理,并且它们都支持 iPhone 的倒置旋转。我知道您说您从单视图应用程序模板开始,但应该没有其他原因导致旋转被阻止。

编辑:您应该检查的另一件事是您的目标设置。此处的“支持的界面方向”部分可能会覆盖您的自定义旋转代码。

于 2013-05-30T18:24:42.290 回答