在IOS5中禁用横向方向

时间:2012-12-14 05:44:54

标签: iphone objective-c ios landscape uiinterfaceorientation

我希望在我的应用程序中消除横向方向,这是为IOS 5构建的。在IOS 6中,我知道这是可能的 - 但在早期版本中它似乎对我不起作用。

我在plist文件中只设置了两个方向(纵向上的主页按钮和底部带有主页按钮的纵向按钮)。无论如何,景观仍然在IOS 5中出现。

我还需要做些什么来消除这种情况吗?

2 个答案:

答案 0 :(得分:1)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
   // return (interfaceOrientation == UIInterfaceOrientationPortrait);
   if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
   return NO;
 }
 else
 {
   return YES;
 }

}

在.m文件中将此代码写入ios5方向

让我知道它是否正常工作....

快乐编码!!!!

答案 1 :(得分:0)

这会奏效。转到故事板取消选择您不想要的方向,并在视图控制器中,编写此代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}
相关问题