2012-05-02 50 views
0

我正在使用一些viewControllers的應用程序。當我在橫向/縱向模式下從一個視圖推到另一個視圖並以相同模式移回時,調用的shouldAutorotateToInterfaceOrientation方法返回。關於shouldAutorotateToInterfaceOrientation方法

但是當相同的步驟重複,並在第二個或第三個視圖中更改方向並向後移動時,則不調用shouldAutorotateToInterfaceOrientation方法。並且視圖控件受到干擾。

請給出一個相同的解決方案。

感謝,

回答

1

如果我正確理解你的問題,你想shouldAutorotateToInterfaceOrientation得到叫上第二或第三的viewController viewControllers的堆棧上時的設備改變方向。

shouldAutorotateToInterfaceOrientation只在頂級viewController上被調用。如果在第二個或第三個viewController的方法中執行任何佈局代碼,則代碼不會執行。

解決方案很簡單,很多都取決於您的代碼。這是一個應該工作(沒有在Xcode測試)。在你的頂部視圖控制器的shouldAutorotateToInterfaceOrientation方法,添加類似:

for (UIViewController *vc in [self childViewControllers]) 
{ 
    [vc shouldAutorotateToInterfaceOrientation]; 
} 

如果你有一個指向特定childViewController,你可以專門調用它。從文檔

注:

此方法的實現應該基於interfaceOrientation參數的值簡單地返回YES或NO。不要嘗試獲取interfaceOrientation屬性的值或檢查UIDevice類報告的方向值。您的視圖控制器可以支持某個給定的方向,或者不支持。

做任何佈局,您可以使用:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

希望這有助於!