Iphone iOS:是否阻止视图方向切换?

Iphone iOS:是否阻止视图方向切换?,iphone,ios,uiview,orientation,Iphone,Ios,Uiview,Orientation,在我的应用程序的构建设置中,我检查了所有支持的方向(除了倒置) 但是,当我启动应用程序时,某些不打算在纵向显示的视图将自动旋转并截断一半的视图。我不希望这些视图旋转 我怎样才能防止这种情况?我试过使用: -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationLandsc

在我的应用程序的构建设置中,我检查了所有支持的方向(除了倒置)

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

我怎样才能防止这种情况?我试过使用:

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

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

但该设备仍希望在可能的情况下改变方向。任何帮助都很好。

此方法已被弃用,不会在iOS 6中调用。更多信息,请参阅苹果的文档或关于新方法的1000个问题之一。

您不想旋转的视图是否嵌入在导航栏或选项卡栏中?如果是这样的话,我也面临着同样的问题。您需要为选项卡栏/导航栏分配一个类,并覆盖ios 6的新方法,如下所示:

-(BOOL)shouldAutoRotate
{
return NO;
}
如果这是你的问题,请告诉我。我还必须使用NSNotificationCenter实现方向更改,以允许在我的一个子视图上旋转。如果这是你要找的,我会贴出来的


让我知道

shouldAutorotateToInterfaceOrientation
不推荐使用。新的更换件是
应自动旋转
。要在返回
shouldAutoRotate
的值之前描述界面方向之间的关系,请使用UIViewController的
interfaceOrientation
属性。例如,您可以有如下内容:

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