我有一個使用6.1 SDK的Monotouch 6.0.10 iPhone應用程序,但定位到iOS 4.0及更高版本,我試圖強制其中一個視圖以縱向,使用ShouldAutorotateToInterfaceOrientation。我意識到現在已經棄用,但仍然需要支持iOS4/iOS5設備。ShouldAutorotateToInterfaceOrientation在iOS6設備上被忽略,使用標籤欄控制器
要嘗試隔離問題,我寫了一個最小測試應用程序。它是無XIB的,並且有一個帶有一個選項卡的UITabBarController。該選項卡有一個UINavigationController,而UINavigationController有一個UIViewController(帶有一個hello world按鈕來點擊)。
在AppDelegate中我有:
tabController = new TabController();
window.RootViewController = tabController;
在的UITabBarController,並在UINavigationController的我:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
在的UIViewController我有:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
if (toInterfaceOrientation == UIInterfaceOrientation.Portrait)
{
return true;
}
else
{
return false;
}
}
好了,上至少iOS 6.1設備,那些ShouldAutorotateToInterfaceOrientation似乎是完全的忽略。那裏的斷點沒有達到,如果我強迫它們在任何情況下都返回錯誤,旋轉仍然發生。
我的理解是ShouldAutomaticallyForwardRotationMethods默認爲true,因此似乎沒有提供解決方案。已經梳理,沒有運氣的論壇,除了格倫·施密特這裏建議:iOS 6 rotations: supportedInterfaceOrientations doesn´t work?但不幸的是,我失去了對如何翻譯,爲的MonoTouch:
QUOTE
If you want to replicate the pre-iOS 6 behaviour where all the views in the navigation stack/tab bar have to agree on an allowable set of orientations, put this in your subclass of UITabBarController or UINavigationController:
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger orientations = [super supportedInterfaceOrientations];
for (UIViewController *controller in self.viewControllers)
orientations = orientations & [controller supportedInterfaceOrientations];
return orientations;
}
所享有
我明白此外,我甚至不能希望通過ShouldAutoRotate/SupportedInterfaceOrientations來爲我的iOS6用戶解決這個問題,因爲這會導致iOS4/IOS5旋轉失敗。
任何建議非常感謝!
Bill。