iPad兼容模式下的iPhone应用程序在横向上有奇怪的布局(我强迫肖像)

时间:2015-03-06 08:31:40

标签: ios iphone ipad ios8 uiinterfaceorientation

问题

正如您所看到的,在横向模式下在iPad上启动时,我的iPhone应用程序布局非常奇怪。我强制应用程序的方向为纵向,但仅在横向模式的iPad上(当我启动应用程序时)似乎将视图在纵向容器中旋转90度。此外,状态栏似乎是一个黑条,位于屏幕中间。

当我从纵向模式启动时,应用程序似乎正常工作。

在横向模式下使用iPad启动应用时 iPad compatibility mode landscape

以纵向模式启动iPad时使用 iPad compatibility mode portrait

我的代码&构造

该应用在info.plist中启用了所有4个方向(因为我会动态切换方向,具体取决于viewController处于活动状态)。

我使用以下方法强制该应用在第一个viewController中成为肖像

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

我尝试将shouldAutorotate设置为NO,但这没有任何区别。

我在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];
}

奇怪的是,一切都是100%正确的iPhone测试。只有iPad兼容模式才会出现此问题。

问题

如何为iPad兼容模式解决此方向问题?似乎我遗漏了一些仅适用于iPad兼容模式的东西,因为iPhone不会发生这种情况。

1 个答案:

答案 0 :(得分:0)

我在Ashraf Tawfeeq的帮助下修复了问题。我仍然从AppDelegate的didFinishLaunchingWithOptions中获得了代码,用于切换不同设备的故事板文件。

我删除了相应的代码,并将我应用的Main Interface中的info.plist设置为我的故事板文件。

[[UIApplication sharedApplication] setStatusBarHidden:NO];

if ([self.window respondsToSelector:@selector(tintColor)]) {
    self.window.tintColor = [UIColor whiteColor];
}

现在,应用程序在iPad上正确启动了方向。

相关问题