2011-08-27 83 views
1

我在UISplitViewController上有旋轉問題。在我的情況下,在調用splitViewController(這個splitViewController是窗口的根視圖)的現有模式後,顯示另一個視圖。當該模態視圖旋轉時,splitView旋轉不正確。當modalView旋轉時,iPad的UISplitViewController旋轉不好

splitView看起來像旋轉一樣,但DetailViewController保持它的樣子,並且RootViewController完全不顯示。它仍然像肖像模式。似乎splitView旋轉,但不是底層視圖(DetailViewControllerRootViewController)。

我嘗試在modalView上實現willRotateToInterfaceOrientation,並使用委託調用splitView的willRotateToInterfaceOrientation方法。

這是我在modalView實現:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
    [delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
} 

其結果是,在DetailViewController正確的行爲,但不與RootViewController。它保持隱藏。在用戶手動旋轉到縱向並返回到橫向後,它將重新出現。但顯然用戶不希望這樣。

這是我做的呈現modalView時:

ModalViewController *modalView = [[ModalViewController alloc] init]; 
MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate]; 
[delegate.splitViewController presentModalViewController:modalView animated:YES]; 
[modalView release]; 

有沒有一種方法,以顯示在這種情況下,RootViewController?或者是我的做事不對?

編輯: 似乎所有的意見都沒有按照modalView旋轉。 RootViewController和DetailViewController都沒有旋轉(在兩個ViewController上都沒有調用the didRotateFromOrientation)。所以現在我假設它不會在設備/ modalView之後旋轉。

+0

您是否試圖從'DetailViewController'中直接顯示您的modalViewController,而不是直接從UISplitView中顯示? –

+0

我試過了,它不工作。到目前爲止,我所做的解決方案是獲取'appDelegate'並獲取splitViewController來調用'willRotateToInterfaceOrientation'兩次。一個在'modalView'的'willRotateToInterfaceOrientation'方法中,一個在'RootViewController'的'willAppear'方法中。 但是這種方法仍然有問題。 'DetailViewController'仍然顯示導航按鈕,就像在縱向模式下一樣。我仍在研究這個。 – Kurotsuki

+0

我有同樣的問題。看看我的解決方案在這裏http://stackoverflow.com/questions/7767302/how-to-inform-the-parent-viewcontroller-about-the-changed-screen-orientation-in/10623628#10623628 – HammerSlavik

回答

1

好的。我的問題已解決。 我做了什麼是我寫的評論Shurakov的評論。

我獲取appDelegate並獲取splitViewController來調用willRotateToInterfaceOrientation。

MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
[delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

我做到了兩次,因爲只有一個似乎沒有工作(我不知道爲什麼)。一個在modalViewControllerwillRotateToInterfaceOrientation方法,一個在RootViewControllerwillAppear方法。

爲了通過在RootViewControllerwillAppear方法調用invalidateRootPopoverButtonItem移除DetailViewController導航/酥料餅的按鈕,我簡單無效該按鈕。這就是它看起來像在這個特別的方法(在modalViewController第一個,我只是通過willRotateToOrientation命令splitViewController):

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 
if (UIInterfaceOrientationIsLandscape(orientation)) { 
    MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [delegate.splitViewController willRotateToInterfaceOrientation:orientation duration:1]; 
    [[[delegate.splitViewController viewControllers] objectAtIndex:1] invalidateRootPopoverButtonItem:self.rootPopoverButtonItem];   
} 

希望這可以解釋我是如何克服我的問題,並幫助任何人誰了和我一樣的問題。