【问题标题】:iPad view appears sidewaysiPad 视图横向显示
【发布时间】:2010-09-23 17:11:01
【问题描述】:

我正在开发仅支持横向模式的 iPad 应用(不会提交到 App Store)。

应用程序中的大多数视图都被推送到带有隐藏导航栏的 UINavigationController。

当我在前面提到的 UINavigationController 的顶视图控制器中添加以下代码时,new UINavigationController (navController) 以纵向模式创建并出现在侧面和屏幕外。

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
// viewController.view is landscape in MyView.xib

// myViewController is created in landscape mode
NSLog(@"%@", NSStringFromCGRect(myViewController.view.frame)); // {{0, 0}, {1024, 704}}

UINavigationController *navController = [[UINavigationController alloc]
    initWithRootViewController:myViewController];

// navController is created in portrait mode (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{0, 0}, {768, 1024}}

[self presentModalViewController:navController animated:YES];

// navController is shifted off-screen after it is presented modally (why?)
NSLog(@"%@", NSStringFromCGRect(navController.view.frame)); // {{1024, 0}, {748, 1024}}

我找不到发生这种情况的任何可能原因,也无法弄清楚如何将视图重新定向为横向模式;我可以改变它的框架,但它的内容仍然是横向的。

我尝试将以下内容添加到 MyViewController.m 无济于事:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return !UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

我什至尝试将此代码添加到 UINavigationController 子类中,但也没有用。

【问题讨论】:

    标签: objective-c cocoa-touch ipad ios orientation


    【解决方案1】:

    通过将视图导航控制器添加为我的应用程序根视图的子视图,我能够让视图导航控制器正确定位。

    MyRootViewController *myRootViewController = [[[UIApplication sharedApplication] delegate] myRootViewController];
    [myRootViewController presentModalViewController:navController animated:YES];

    此代码在导航控制器的顶部视图控制器中,它是根视图的子视图。

    【讨论】:

      【解决方案2】:

      不确定这是否可行,但您可以将此键添加到 Info.plist 以指示您的应用支持的方向(至少,这将阻止它以纵向启动):

      UISupportedInterfaceOrientations~ipad => (UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight)
      

      【讨论】:

      • 感谢您的建议,但我的 Info.plist 文件已经指定该应用仅支持左右横向。
      猜你喜欢
      • 2014-11-20
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多