2012-07-18 66 views
7

任何嘗試最新的iOS 6測試版(版本2或3)的用戶都有相同的自動旋轉不工作經驗?我不使用情節串連圖板,但純粹的導航控制iOS 6屏幕旋轉,不使用故事板

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; 
[self.window addSubview:navController.view]; 

而且有:

- (BOOL)shouldAutorotateToInterfaceOrientation: ](UIInterfaceOrientation)interfaceOrientation 
{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} else { 
    return YES; 
} 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

但IOS沒有擁護可言,做工精細與3GS/4S和以前所有的iOS 4.3,5.0.5.1模擬器,但iOS 6似乎只是越野車

回答

0

的解決方案是: 由於我的應用程序試圖從4.3+支持,我必須使用導航控制器做每一個視圖切換。

ios6似乎代表導航控制器,我必須定義我自己的導航控制器,並設置條件和功能來改變其旋轉行爲。當我加載一個視圖,然後我做([self.navigationCOntroller setEnableLandscape:(BOOL)false])。這樣你就可以完全控制你的導航控制器。

注:我沒有嘗試覆蓋導航控制器的方法,但似乎只是被忽略。 (這隻發生在iOS 6.0以上),還沒有測試6.1,所以不知道它是否得到了解決(請讓我知道它是否如此)

10

iOS 6中的自轉正在改變。在iOS 6中,不推薦使用UIViewControllershouldAutorotateToInterfaceOrientation:方法。取而代之,您應該使用supportedInterfaceOrientationsshouldAutorotate方法。

Read more here

+0

何時調用shouldAutorotate函數?當我旋轉屏幕時,它似乎永遠不會被調用...或者,這可能與模擬器有關嗎? – shim 2012-10-26 04:57:30

+0

查看我的問題在這裏http://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape – 2012-10-27 15:12:06

7

代替[self.window addSubview:navController.view];

插入self.window.rootViewController = navController;

+0

爲了提高你的文章的質量,請包括如何/爲什麼你的答案將解決問題。 – 2012-10-03 00:29:51

+1

你剛剛救了我的命。過去3個小時我嘗試了其他的一切。我一直在收到回調,但iOS忽略了我放在那裏的一切。謝謝你,謝謝你,謝謝你! – gilm 2012-10-05 11:00:52

+0

在iOS上的iOS6 sdk上編譯時可以使用,但在iOS6上編譯時,它不適用於我在iOS5 os上運行的sdk! 您是否嘗試過在iOS5上如何使用它? – Koen 2012-10-24 12:29:02