繁体   English   中英

我如何在iPhone iOS6中为UINavigationController处理UIInterfaceOrientationPortraitUpsideDown

[英]How can i handle UIInterfaceOrientationPortraitUpsideDown for UINavigationController in iPhone iOS6

我知道:默认情况下,对于iPad习惯用语,应用程序和视图控制器的受支持的界面方向设置为UIInterfaceOrientationMaskAll,对于iPhone习惯用语,设置为UIInterfaceOrientationMaskAllButUpsideDown。 因此,当我使用Single View Application模板创建一个新项目时,要在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。 我该如何解决? 我尝试在较旧的主题中搜索一些代码,但仍然无法正常工作。

myNavigationController是属性吗? 您将其引用为myNavigationControllerself.myNAvigationController 似乎不一致,尤其是因为您初始化了引用ivar的对象,然后使用该属性设置了窗口的rootViewController时。

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

话虽如此:您可能需要检查所有ViewController是否实现了旋转委托,并且它们都支持iPhone的上下旋转。 我知道您说过您是从单视图应用程序模板开始的,但是应该没有其他原因阻止旋转。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM