【发布时间】: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