[英]iPhone app on iPad compatibility mode has strange layout in landscape (while I force portrait)
The Problem 问题
As you can see, my iPhone app has a very strange layout when starting on iPad in landscape mode. 正如您所看到的,在横向模式下在iPad上启动时,我的iPhone应用程序具有非常奇怪的布局。 I force the orientation of the app to portrait, but only on the iPad in landscape mode (when I start the app) seems to put the view 90 degrees turned in a portrait container.
我强制应用程序的方向为纵向,但仅在横向模式的iPad上(当我启动应用程序时)似乎将视图在纵向容器中旋转90度。 Also, the status bar seems to be a black bar and in the middle of the screen.
此外,状态栏似乎是一个黑条,位于屏幕中间。
The app seems to work properly when I start it from portrait mode. 当我从纵向模式启动它时,该应用程序似乎正常工作。
When starting the app with the iPad in landscape mode 在横向模式下使用iPad启动应用程序时
When starting the app with the iPad in portrait mode 在纵向模式下使用iPad启动应用程序时
My code & configuration 我的代码和配置
The app has all 4 orientations enabled in the info.plist
(because I dynamically switch orientation depending on which viewController
is active). 该应用程序在
info.plist
启用了所有4个方向(因为我动态切换方向取决于哪个viewController
处于活动状态)。
I force the app to be portrait in the first viewController
by using: 我通过使用以下方法强制应用程序在第一个
viewController
成为肖像:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
I tried setting shouldAutorotate
to NO
, but this makes no difference. 我尝试将
shouldAutorotate
设置为NO
,但这没有任何区别。
The way I am starting my app in the AppDelegate
didFinishLaunchingWithOptions
is: 我在
AppDelegate
启动应用程序的方式didFinishLaunchingWithOptions
是:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// 1
UIStoryboard *mainStoryboard = nil;
mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// 2
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
if ([self.window respondsToSelector:@selector(tintColor)]) {
self.window.tintColor = [UIColor whiteColor];
}
Strangely, everything goes 100% right with testing on an iPhone. 奇怪的是,一切都是100%正确的iPhone测试。 Only the iPad compatibility mode has this issue.
只有iPad兼容模式才会出现此问题。
Question 题
How can I solve this orientation problem for the iPad compatibility mode? 如何为iPad兼容模式解决此方向问题? It seems I am missing something that only applies for the iPad compatibility mode, as nothing like this happens for the iPhone.
似乎我遗漏了一些仅适用于iPad兼容模式的东西,因为iPhone不会发生这种情况。
I fixed the problem with the help of Ashraf Tawfeeq . 我在Ashraf Tawfeeq的帮助下解决了这个问题。 I still had the code in the AppDelegate's
didFinishLaunchingWithOptions
from way back, that switched storyboard files for different devices. 我仍然从AppDelegate的
didFinishLaunchingWithOptions
获得了代码,用于切换不同设备的故事板文件。
I removed the corresponding code and set the Main Interface
in my app's info.plist
to my storyboard file. 我删除了相应的代码,并将我的应用程序的
info.plist
的Main Interface
设置为我的storyboard文件。
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if ([self.window respondsToSelector:@selector(tintColor)]) {
self.window.tintColor = [UIColor whiteColor];
}
Now the app correctly turns orientation on startup on the iPad. 现在,应用程序正确地在iPad上启动方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.