简体   繁体   English

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

[英]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启动应用程序时 iPad兼容模式的风景

When starting the app with the iPad in portrait mode 在纵向模式下使用iPad启动应用程序时 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.plistMain 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.

相关问题 应用程序支持ipad和iphone中的应用程序横向和纵向模式 - App support the app Landscape and portrait mode in both ipad and iphone Ipad在横向模式下和iphone在纵向模式下 - Ipad in landscape mode and iphone in portrait mode 如何在Adobe AIR应用程序中强制iPad中的横向和iPhone中的纵向? - How can i force landscape in iPad and portrait in iPhone in an Adobe AIR app? 启动应用程序Iphone纵向和Ipad横向 - Launch app Iphone portrait, and Ipad landscape iPhone应用程序在横向和纵向模式下都可以正常工作,但在iPad上只能在一种模式下工作? - Iphone app is working fine in both landscape and portrait mode but in ipad it only works in one mode? 支持iPhone上的纵向方向的通用应用程序和iPad上的横向+纵向 - Supporting Universal App with Portrait Orientation on iPhone and Landscape+Portrait on iPad iPhone和iPad纵向模式应用程序的不同反应 - iPhone and iPad Portrait mode app different reaction 横向模式iPad应用程序中的坐标对应于纵向模式 - Coordinates in landscape mode iPad app correspond to portrait mode 使用横向模式在iPad中启动iPhone App - Launch iPhone App in iPad with landscape mode 在iPad的iPhone模式下,应用以横向显示 - App displaying in landscape when on iPhone mode on iPad
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM