2013-03-18 84 views
-1

我有一個應用程序,它具有UIViewController作爲根視圖控制器(不是TabBarNavigationController應用程序!)。這個程序是通用的。它應該始終是iPhone的肖像,並始終是iPad的風景。通用應用程序中的iOS 6.0方向問題

我試過以下,但我認爲這是iOS 5的代碼,因爲它沒有被稱爲iOS 6中:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
    else 
    { 
     return (interfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight)); 
    } 
} 

任何幫助表示讚賞!

+1

請閱讀'UIViewController'的文檔。從iOS 6開始,方向更改處理有所不同。文檔涵蓋了這些更改。關於這個話題也有許多現有的問題。 – rmaddy 2013-03-18 20:05:05

+0

它實際上是一個混合:D shouldAutorate是ios6,其他ios5 – 2013-03-18 20:25:20

+0

正在使用xib或故事板? – 2013-03-18 20:37:49

回答

0

下面是iOS 6的代碼集。它使用了蒙版。如果是針對整個iPhone一個方向和iPad一個方向,那麼在項目級別,您可以通過取消選擇與您不想要的方向相關的按鈕來設置該方向。這就是說,如果iPhone中的所有視圖都是相同的,並且iPad也適用。如果你想用代碼做到這一點,下面的工作將完成這項工作:

- (BOOL) shouldAutorotate 
{ 
return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

只是採取你不想用的方向。請讓我知道你是否需要更多的幫助。

+0

謝謝!爲了使它適用於我的情況,我修改了一下代碼:' - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { 如果(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone) { 返回UIInterfaceOrientationMaskPortrait; } return UIInterfaceOrientationMaskLandscape; }' – sixstatesaway 2013-03-18 21:01:08

+0

很高興能有所幫助。快樂編碼:) – 2013-03-18 21:03:23