通过分体式视图控制器启动的模态视图的问题

问题描述:

我已经创建了一个以模态视图初始页面开始的分体视图应用程序。问题是模式视图总是以纵向模式启动,即使ipad处于横向模式。如果我旋转ipad几次,它会适当旋转。我在Info.plist中设置了UIInterfaceOrientation,但它没有任何影响。在didFinishLaunchingWithOptions通过分体式视图控制器启动的模态视图的问题

,我使用下面的代码

... 
[self.window addSubview:splitViewController.view]; 
SplashViewController *modalView = [[SplashViewController alloc] intiWithNibName:nil bundle:nil]; 
modalView.modalPresentationStyle = UIModalPresentationFullScreen; 
[splitViewController presentModalViewController:modalView animated:YES]; 
... 

我如何能确保模态视图中的风景启动有什么建议?

+0

同样的问题~~~~ – ludo 2011-01-25 10:10:01

我觉得这是更好的方式来做到这一点:

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

更简单:return(UIInterfaceOrientationIsLandscape(interfaceOrientation)); – atticus 2011-10-14 02:22:00

在启动模态视图的文件中,您需要更改/覆盖以下功能。你可以简单地复制和粘贴下面的代码,你应该能够启动模式视图中肖像风景模式:

- (BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

好运。

编辑:我说肖像模式,而不是我的意思是:景观模式。

+0

感谢您的答复。我正在从didFinishLaunchingWithOptions方法启动模态视图。上面的方法已经在分割视图和模态视图控制器本身中出现的视图控制器的.m文件中设置。全部无效 – Aaron 2011-01-21 19:35:39

我在使用Matt Gemmell's MGSplitViewController时遇到类似问题。在我的情况下,通过尝试在详细视图控制器(即UISplitViewController标准中的“右侧”窗格)中以FormSheet模式打开模式视图控制器,我的模式视图强制将界面旋转为纵向。 我找到了解决方案通过重写模式视图控制器 - > shouldAutorotateToInterfaceOrientation:并让他返回NO:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Overriden to allow any orientation. 
    return NO; 
}

在当模式将被提出,由于某种原因,操作系统试图迫使它这样肖像。通过回答NO,视图不再旋转,一切正常。

+0

你不能实际返回NO作为答案,因为你会得到一个运行时警告,抱怨没有支持的方向,它将默认为肖像。尽管你的答案帮助我弄清楚了。谢谢! – Brooks 2012-03-29 20:13:45