Iphone iOS仅旋转视图一个视图控制器';s观点

Iphone iOS仅旋转视图一个视图控制器';s观点,iphone,objective-c,ios,autorotate,Iphone,Objective C,Ios,Autorotate,我在一个项目中有两个视图控制器。但是,我希望其中一个视图控制器自动旋转,另一个不自动旋转 如果我设置主项目设置,如下所示: 然后,所有视图控制器自动旋转,而不考虑视图控制器中我不想自动旋转的以下代码: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrienta

我在一个项目中有两个视图控制器。但是,我希望其中一个视图控制器自动旋转,另一个不自动旋转

如果我设置主项目设置,如下所示:

然后,所有视图控制器自动旋转,而不考虑视图控制器中我不想自动旋转的以下代码:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return YES;
    }
    return NO;
}
但是,如果如下图所示设置主项目设置,则我不希望自动旋转的视图控制器不会自动旋转,但这也意味着我不希望自动旋转的视图控制器也不能自动旋转

我必须如何将主项目(plist文件)设置与视图控制器的设置集成,以便一个视图控制器将自动旋转,而另一个视图控制器将不自动旋转

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
在iOS 6中被折旧了,所以如果你的项目就是这样运行的,那就是它不起作用的原因。您需要做的是实施:

- (NSUInteger)supportedInterfaceOrientations
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
第一个将告诉控制器允许使用哪个方向,第二个将告诉控制器首先使用哪个方向。请注意,只有当方法shouldAutorotate:返回YES时,才会调用第一个方法

以下是可用于supportedInterfaceOrientations的常量:

UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown

请注意,这些仅适用于iOS 6.0。

假设我使用的是tabbarController&iOS。请检查这两个ViewController的关系如何?例如推送关系或模式关系。
//In First View Controller

//BOOL activeStatus;

-(void)viewWillAppear:(BOOL)animated
{
 activeStatus=YES;
}


-(void)viewWillDisappear:(BOOL)animated
{
 activeStatus=NO;
}

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

return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
//In Second View Controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

 return YES;
}