2012-06-25 136 views
0

我目前正在研究iPad上的應用程序。它只支持縱向,而不支持橫向。應該在.m文件中編輯或添加什麼代碼(什麼文件)以使其支持剩下的格局?我需要應用程序中的所有頁面來支持它。iPad IOS5方向

回答

1

每一個的UIViewController需要實現這個方法:如果你想支持只有少數

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 

(剛上任何你不希望返回NO被支持):

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    //Allow Original Portrait 
    if(interfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     return YES; 
    } 
    //Allow Upside Down 
    else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     return YES; 
    } 
    //Allow Landscape Left 
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     return YES; 
    } 
    //Allow Landscape Right 
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     return YES; 
    } 
} 
+0

但是,您不應該返回YES,因爲它會支持*所有*方向... – 2012-06-25 15:46:28

+0

我想你確實是正確的,我從這個問題假設他可能只是想支持所有事情......只是編輯答案來支持任何事情,用一種非常簡單的方法來不支持特定的方向如果需要... @ H2CO3 – Highrule

+0

謝謝,你的回答非常好。 – 2012-06-25 15:56:17

0

在每個視圖控制器中,您需要添加以下代碼:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOritentationPortraitUpsideDown)); 
} 
+1

但是,我相信Apple **強烈建議允許在iPad應用程序中使用所有方向。所以除非你有足夠的理由不支持風景,否則你的應用可能會被拒絕。 – Jeremy1026