2012-10-16 52 views
1

在我的应用程序的构建设置中,我已经检查了所有支持的方向(除了倒置)。iOS:防止切换时查看方向?

但是,当我启动应用程序时,某些视图不能用纵向显示,将自动旋转并截断视图的一半。我不希望这些视图旋转。

我该如何预防? ive试过使用:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    return YES; 
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    return YES; 

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

但是,该设备仍然想要时,它可以变成肖像。任何帮助都会很棒。

+0

http://stackoverflow.com/questions/2868132/shouldautorotatetointerfaceorientation-doesnt-work – prashanth

回答

0

此方法已弃用,不会在iOS 6中调用。有关更多信息,请参阅Apple的文档或关于新方法的SO上千个问题之一。

0

您不想旋转的视图嵌入导航栏或标签栏中?如果有的话,我也面临同样的问题。你需要一个类分配到标签栏/导航栏,并覆盖iOS 6中的新方法:

-(BOOL)shouldAutoRotate 
{ 
return NO; 
} 

让我知道,如果这是你的问题的类型。我还必须使用NSNotificationCenter实现方向更改,以便在我的一个子视图上旋转。我会张贴如何,如果这是你的要求。

让我知道!

0

shouldAutorotateToInterfaceOrientation已弃用。新的替代品是shouldAutoRotate。为了在返回shouldAutoRotate的值之前在界面方向之间进行区分,请使用UIViewControllers的interfaceOrientation属性。例如,你可能有这样的事情:

-(BOOL)shouldAutoRotate{ 
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait){ 
     return YES; 
    } 
    else { 
     return NO; 
    } 
}