2012-06-25 70 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