2012-10-05 103 views
0

我在使應用的方向正常工作時遇到了一些麻煩。簡而言之,我有兩個視圖控制器,我將在我的應用程序中進行切換。 ViewControllerA只能以縱向或倒置顯示。 ViewControllerB可以以四種方向中的任何一種顯示。方向無法正常工作

這看起來應該是非常簡單的。我不知道該怎麼做,但我想如果我只是撥弄shouldAutorotateshouldAutorotateToInterfaceOrientation:supportedInterfaceOrientations,那麼我應該得到我想要的。出於某種原因,info.plist中的接口方向是完全覆蓋視圖控制器中的任何代碼。如果我只允許肖像在info.plist但允許在我的viewcontroller中的一切,它旋轉。而唯一被調用的方法是supportedInterfaceOrientations(其中我返回UIInterfaceOrientationMaskAll)。同樣,如果我允許info.plist中的每個方向,旋轉設備也會旋轉viewController,即使在我的代碼中我禁止任何不是縱向的方向。

我真的不知道我做錯了什麼。有人可以請幫忙,並告訴我我的方向代碼應該看起來像ViewControllerAViewControllerB的片段,以及在info.plist中應該選擇什麼樣的方向。謝謝!

回答

0

在功能

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

您應返回true要旋轉到所有的接口,讓說你想人像只

return interfaceOrientation == UIInterfaceOrientationPortrait; 

如果你想要的一切,但顛倒

return !(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 

在plist本身上它設置了更多的全局值,所以如果這個選項無效,你的代碼將不會運行能夠。你必須授予plist能夠爲兩個視圖做到這一點。

希望這會有所幫助。

0

iOSA中不推薦使用shouldAutorotateToInterfaceOrientation方法,而是在所有當前的全屏視圖控制器中實現supportedInterfaceOrientations和shouldAutorotate方法。

還要確保您的應用程序在主窗口上執行了setRootViewController。

0

試試這個在您的AppDelegate.m

// [window_ addSubview:navController_.view]。

[window_setRootViewController:navController_];