Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS防止在某些视图中旋转_Iphone_Ios_Ipad - Fatal编程技术网

Iphone iOS防止在某些视图中旋转

Iphone iOS防止在某些视图中旋转,iphone,ios,ipad,Iphone,Ios,Ipad,我有一个viewcontroller和它的视图,在iPad中只支持横向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationPortrait) return NO; else return YES; } 但我有一个电影播放器,只需要在肖像。因

我有一个viewcontroller和它的视图,在iPad中只支持横向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == UIInterfaceOrientationPortrait)
    return NO;
else
    return YES;

}
但我有一个电影播放器,只需要在肖像。因此,从这个角度来看,我这样做:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == UIInterfaceOrientationPortrait)
    return YES;
else
    return NO;
}

我的问题是,如果我在第一个viewcontroller中将“纵向”设置为“否”,那么我的第二个视图控制器将永远不会旋转为“纵向”。第二个ViewController作为第一个视图的子视图添加。如何使视图1不旋转为纵向,但使视图2不旋转为横向。此应用程序用于演示目的,因此我只是在寻找有关此应用程序的技术答案。

我不相信将其添加为子视图时可能会出现这种情况。尝试将新视图推到不可见的UINavigationController堆栈上,以实现您的目标。当从第一个视图转到第二个视图时,这会起作用,但是当第二个vc弹出时,让第一个视图旋转回其原始位置是非常棘手的,因为苹果不希望您这样做。这里有一个非常非常恶作剧的把戏,把它强加于流行音乐:

-(void)viewDidAppear:(BOOL)animated {   
    UIViewController *c = [[UIViewController alloc] init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [c release];    
}

当我在过去遇到这个问题时,我做了以下工作:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   if(mayRotate){
      return YES;
   }else{
      return NO;
   }
}

我认为还有一点,但你应该有这个想法。

我不是100%确定,但因为我们已经在讨论黑客解决方案,我相信你可以直接用-[UIScreen SetStatusBaroOrientation:animated:]设置设备的旋转。我从未尝试过,而且文档中有一些可怕的警告,所以这可能不是最好的主意…真的。。。我也读到过这种方式。但正如您所说,这是一个演示,所以黑客现在可能会工作;)谢谢SetStatusBaroOrientation和[[UIDevice currentDevice]setOrientation:]甚至不能重写shouldAutoRotate属性