2011-04-25 41 views
7

可能重複:
ViewController not responding to didRotateFromInterfaceOrientationdidRotateFromInterfaceOrientation旋轉時不會觸發?

我在與didRotateFromInterfaceOrientation方法在我的ViewController子類的一個不點火的麻煩。

我有一個iPad應用程序w/UISplitViewController作爲主視圖。在細節方面,我使用「隱藏」(無工具欄,導航欄)導航控制器進行懶惰視圖切換。我想要捕捉didRotateFromInterfaceOrientation的ViewController在navcontroller層次結構中有兩層。 (這一切都不應該有所作爲,但我包括此情況下的信息還有,我不知道某些特定的情況下約)

我:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 

// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    NSLog(@"Rotate Go!"); 
} 

視圖旋轉就好了,但是RotateFromInterfaceOrientation從不會觸發。

任何想法我失蹤?

+0

你有沒有uitabbar?因爲如果你是這樣的話,你應該創建一個uitabbar類,並且在這個類上實現「shouldAutorotateToInterfaceOrientation」,這樣所有其他的控制器都會收到這個循環消息。 – 2011-04-25 01:40:17

+0

沒有。我使用的UISplitViewController,UIToolbar和UINavigationController(工具欄隱藏,所以不同的視圖共享其他工具欄)。但沒有UITabBar ... – DOOManiac 2011-04-25 03:26:27

+0

根據蘋果,你的UISplitViewController必須是你的應用程序窗口中的根視圖。如果情況不是這樣,你可以體驗到一些奇怪的東西。檢查這個線程http://stackoverflow.com/questions/2734016/uisplitviewcontroller-doesnt-autorotate – 2011-04-25 11:52:09

回答

0

嗯,我始終沒弄明白,爲什麼事件無法,但我沒有想出一個解決辦法:

在兩種UISplitViewController委託方法,splitViewController:willHideViewController:withBarButtonItem:forPopoverController:splitViewController:willShowViewController:invalidatingBarButtonItem:,我檢測是否不是我的觀點是可見的,然後在這裏做我的旋轉邏輯。

5

如果您的UIViewController是某個根視圖中的子項,則IB不會將其作爲子控制器默認添加到根控制器。解決這個問題的最簡單的方法是修改你的根控制器:

- (void)viewDidLoad 
{ 
    [super viewDidLoad];  
    [self addChildViewController:(UIViewController*) self.yourChildController]; 
} 

這應該可以做到。現在你的孩子控制器將收到兩個:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

消息。

+0

謝謝!這只是解決了我與UISplitViewController沒有得到旋轉事件的問題。 – cberkley 2012-03-30 18:09:23