2011-04-28 83 views
1

我有幾個視圖都由他們自己的控制器管理,其中一些嵌套。 我想支持旋轉,一些視圖可以旋轉到任何方向,有些只能旋轉到其中一個縱向(正常或顛倒)。多視圖控制器不同的自動旋轉要求

在我的情況下,我需要在我的rootController中實現-shouldAutorotateToInterfaceOrientation以允許任何子視圖旋轉。問題是,rootController不知道它是否應該允許旋轉,因爲它需要問這到子視圖控制器。

在我rootController的-shouldAutorotateToInterfaceOrientation我可以這樣做:

return [self.settingsController shouldAutorotateToInterfaceOrientation]; 

提供旋轉必要的邏輯,但是這會不會做這種正確的方法是什麼? 我的確讀過apple's doc about rotation,但這並沒有被真正的好評。

回答

1

爲了將來的參考,我會回答我自己的問題。

我的問題是,我已經嵌套viewControllers和我通過調用像顯示的子級的viewController的觀點:

self.view = _subLevelViewController.view; 

[self.view addSubview:_subLevelViewController.view]; 

顯然,這樣的嵌套的viewController不是蘋果想讓你做什麼。

你應該1「根的viewController」堅持,​​你應該使用類似的方法顯示其他viewControllers:

[self presentModalViewController:_subLevelViewController animated:YES]; 

關於這個問題的更多信息和一個非常良好的閱讀:
http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/

0

我發現這篇文章和引用的博客是關於做嵌套視圖控制器的最簡潔的指導。這是值得更新:

// "self" is the root view controller. 
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
    // The following is not available until iPhone 5.0: 
    [self presentViewController:self.subViewController animated:YES completion:NULL]; 
else 
    // For iOS 4.3 and earlier, use this (deprecated in 5.0): 
    [self presentModalViewController:self.subViewController animated:YES]; 

我已經離開它空在這裏,但要注意,新的方法可以讓你通過completion: PARAM發送一個內聯函數。根據類ref,它將在subViewController的viewDidAppear:運行後調用。

相關問題