![](/img/trans.png)
[英]App support the app Landscape and portrait mode in both ipad and iphone
[英]iPhone app on iPad compatibility mode has strange layout in landscape (while I force portrait)
問題
正如您所看到的,在橫向模式下在iPad上啟動時,我的iPhone應用程序具有非常奇怪的布局。 我強制應用程序的方向為縱向,但僅在橫向模式的iPad上(當我啟動應用程序時)似乎將視圖在縱向容器中旋轉90度。 此外,狀態欄似乎是一個黑條,位於屏幕中間。
當我從縱向模式啟動它時,該應用程序似乎正常工作。
在橫向模式下使用iPad啟動應用程序時
在縱向模式下使用iPad啟動應用程序時
我的代碼和配置
該應用程序在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不會發生這種情況。
我在Ashraf Tawfeeq的幫助下解決了這個問題。 我仍然從AppDelegate的didFinishLaunchingWithOptions
獲得了代碼,用於切換不同設備的故事板文件。
我刪除了相應的代碼,並將我的應用程序的info.plist
的Main Interface
設置為我的storyboard文件。
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if ([self.window respondsToSelector:@selector(tintColor)]) {
self.window.tintColor = [UIColor whiteColor];
}
現在,應用程序正確地在iPad上啟動方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.