iPad 视图显示为横向
我正在开发一个仅支持横向模式的 iPad 应用程序(不会提交到 App Store)。
应用程序中的大多数视图都被推送到带有隐藏导航栏的 UINavigationController 上。
当我在上述 UINavigationController 的顶视图控制器中添加以下代码时,新 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 子类中,但它也不起作用。
I am working on an iPad app (which will not be submitted to the App Store) which supports only landscape mode.
Most of the views in the application are pushed onto a UINavigationController with a hidden navigation bar.
When I add the following code in the top view controller in the aforementioned UINavigationController, the new UINavigationController (navController) is created in portrait mode and appears sideways and off-screen.
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}}
I cannot find any possible reason for this to occur, nor can I figure out how to reorient the view to landscape mode; I can change its frame but its content is still sideways.
I tried adding the following to MyViewController.m to no avail:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return !UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
I even tried adding this code to a UINavigationController subclass which did not work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将视图导航控制器添加为应用程序根视图的子视图,我能够使视图导航控制器正确定位自身。
此代码位于导航控制器的顶视图控制器中,它是根视图的子视图。
I was able to get the view navigation controller to orient itself correctly by adding it as a subview of my application's root view.
This code is in the top view controller of the navigation controller which is a subview of the root view.
不确定这是否有效,但您可以将此键添加到您的 Info.plist 中以指示您的应用程序支持的方向(至少,这将阻止它以纵向启动):
Not sure if this will work, but you could add this key to your Info.plist to indicate what orientation your app supports (at least, this will prevent it from starting in portrait):