2010-04-29 59 views
6

我最近遇到了一個問題。我的iPad應用程序以某種方式阻止iPad自動旋轉。我的應用程序爲兩個視圖控制器加載一個UISplitView,併爲shouldAutorotateToInterfaceOrientation返回YES。我已經建立了我的info.plist,以包含所有四個方向的「支持的界面方向」鍵。但是,當我運行應用程序時,旋轉設備不會旋轉splitView(即使我正在接收UIDeviceOrientationDidChangeNotification)。另外,當我以不同的方向退出我的應用程序時,它在iPad主屏幕中開始不會自動旋轉到正確的視圖,直到我再次旋轉它而沒有運行我的應用程序....任何想法都將不勝感激...UiSplitViewController不自動旋轉

回答

8

UISplitViewController是我曾經使用過的最氣質的視圖控制器子類之一。爲了使其「完美」工作,它必須必須作爲應用程序窗口中的單個根視圖存在。但是,你可以用一些欺騙手段解決這個問題 - 在我的情況下,我需要一個UITabBarController以及至少兩個不同的UISplitViewController作爲視圖控制器 - 但是你必須考慮涉及旋轉和UISplitViewControllerDelegate回調沒有觸發的奇怪情況。

這裏的希望,Apple的UISplitViewController在未來其他UIKit組件更兼容...

+1

你可以繞過它欺騙你說...什麼欺騙?你逗弄! – radven 2012-07-12 10:11:19

+0

它只是手動轉發適當的旋轉方法。記錄一堆東西,看看有什麼方法,我們沒有被調用。然後,我只是在我的根視圖控制器子類中進行補償,確保子視圖控制器獲得了正確的方法,調整了視圖的大小等。 – LucasTizma 2012-07-12 14:05:07

+0

我現在有同樣的問題,有我的SplitViewController,它們是TabBarController下的選項卡,行爲不穩定,所以很高興知道這不僅僅是我!至少感謝這種安慰! – Gowiem 2013-04-11 22:46:21

0

你說你的第一個問題是,UISplitView阻止你自動旋轉。嘗試使用Splitview的子類,而不是使用ENVILE自動旋轉:

@implementation SplitViewControllerRotating 
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    NSLog(@"SplitViewControllerRotating shouldAutorotate"); 
    return YES; 
} 
@end 

你的第二個問題聽起來很奇怪。你說退出你的應用程序後,你必須旋轉,以便您的iPad識別面向接口。不能幫助你。

+2

我給它一個鏡頭......它沒有工作......是不是UISplitView自動旋轉的目的? – Michael 2010-05-27 18:37:36

+0

有沒有人知道iOS 9上的解決方案?以上回答的答案已棄用。 – vaberer 2015-09-15 09:32:06

0

我現在有同樣的問題。原因是我不小心將的另一個視圖添加到了UISplitViewController視圖的窗口中。刪除額外的視圖使其工作。

1

你的UISplitViewController設置爲你的根視圖控制器嗎?否則,這可能是您的問題的原因。我有一個類似的問題 - 狀態欄會旋轉,但我的細節和主視圖將保持原樣。我重新安排了視圖,以便UISplitViewController是根,然後我的「主菜單」作爲分割視圖頂部的模式視圖控制器呈現,並且使旋轉問題消失。

根據iPad Programming Guide,「分割視圖控制器的視圖應始終安裝爲應用程序窗口的根視圖。」

希望這會有所幫助。

4

我碰到了同樣的問題有兩個下屬UINavigationControllers。在我的情況下,旋轉開始工作,一旦我取代了shouldAutorotateToInterfaceOrientation:在左側控制器中總是返回'YES'。

+2

masterView和detailView都需要支持YES,無論您想要旋轉的方向如何。如果其中一個沒有返回YES,它將不會旋轉。我錯過了這個微妙的細節,我的masterView只支持肖像。希望這可以幫助別人。 – sasquatch 2012-02-09 16:56:05

1

我發現這做工精細 - 提供UISplitViewController的兩個孩子實施shouldAutorotateToInterfaceOrientation

I.e如果您有類似:

 MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil]; 
     UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; 

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil]; 
     UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]; 

     self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController]; 

     self.window.rootViewController = self.splitViewController; 

來定義你的NSApplicationrootViewController那麼兩個MasterViewControllerDetailViewController應該實現:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return YES; 
} 

,以確保旋轉的作品。