【问题标题】:How can i handle UIInterfaceOrientationPortraitUpsideDown for UINavigationController in iPhone iOS6我如何在 iPhone iOS 6 中处理 UINavigationController 的 UIInterfaceOrientation Portrait UpsideDown
【发布时间】:2013-04-28 01:15:41
【问题描述】:

我知道:默认情况下,应用程序和视图控制器支持的界面方向设置为 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。我该如何解决?我试图在较旧的主题中搜索一些代码,但仍然无法正常工作。

【问题讨论】:

标签: iphone ios6 orientation


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2012-12-03
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多