iPad模式视图旋转parentViewController视图

iPad模式视图旋转parentViewController视图,ipad,modal-dialog,landscape,autorotate,Ipad,Modal Dialog,Landscape,Autorotate,当应用程序处于横向模式(我计划强制)时,显示模式视图会导致父视图旋转到纵向模式。如果我将shouldAutoRotateToInterfaceOrientation的返回值设置为“否”,则父对象不会旋转,但是模式会从侧面滑入并显示在侧面。下面是显示模态的代码 - (IBAction)loadExistingGame:(id)sender { SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController a

当应用程序处于横向模式(我计划强制)时,显示模式视图会导致父视图旋转到纵向模式。如果我将shouldAutoRotateToInterfaceOrientation的返回值设置为“否”,则父对象不会旋转,但是模式会从侧面滑入并显示在侧面。下面是显示模态的代码

- (IBAction)loadExistingGame:(id)sender {

SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
savedGames.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:savedGames animated:YES];

[savedGames release];
}

根据请求,这里是SavedGamesTableViewController的shouldAutoRotate方法的内容

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}

基于

当应用程序处于横向时 模式(我计划强制的模式), 显示模式视图会导致 要旋转到纵向的父视图 模式

根据要求,这里是 应力自转法 SAVEDGAMESTABLEVEWCONTROLLER

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;

因此,您要说的是,父视图控制器尚未设置为仅使用横向方向强制,当您显示设置为允许所有方向的模式视图时,您想知道为什么将设备旋转为纵向时,父视图会旋转为纵向?我不明白你的问题。。。您不是说父视图控制器当前设置为允许旋转到纵向吗?这种行为不正是应该发生的吗?

好的,我知道需要做些什么来修复它。包含可能方向列表的plist文件需要限制为单个横向视图。仅当方向与plist文件中的唯一方向匹配时,模态表视图的父级需要让shouldAutoRotateToInterfaceOrientation方法返回YES

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


对于相同的方法,modal viewcontroller应该返回NO。

我在调出modal mail视图时遇到了类似的问题。强制旋转对我来说不起作用,但在应用程序的主视图控制器而不是子视图控制器上调用presentModalViewController解决了这个问题。

我看到了同样的行为;在我的例子中,问题是我已经实现了shouldAutorotateToInterfaceOrientation,以便无条件地为父视图控制器返回YES,而不是为呈现的模态视图控制器返回YES。因此,我怀疑Shaggy Frog的评论是关键:无论您是否想要强制使用横向模式,您都需要确保两个视图控制器的shouldAutorotateToInterfaceOrientation实现一致,否则就会出现奇怪的情况

UIViewController *vc = /* create view controller */;
UINavigationController *nc = nil;
if (IOS_VERSION_LESS_THAN_6_0) {
    nc = [[MyCustomNavigationControllerSupportingAllOrientations alloc] initWithRootViewController:vc];
} else {
    nc = [[UINavigationController alloc] initWithRootViewController:vc];
}
[self.navigationController presentModalViewController:nc animated:YES];
在iOS6上,我使用UINavigationController

在iOS6 I之前的子类UINavigationController上,如下所示:

@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController
@end

@implementation MyCustomNavigationControllerSupportingAllOrientations
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end

请在SavedGamesTableViewController中显示
shouldAutoRotateToInterfaceOrientation
的实现。添加了该方法,但它只是锅炉板生成的代码。不,设备未旋转。当显示模态视图时,模态的父级会旋转。除了
SavedGamesTableViewController
,屏幕上是否还会显示其他控制器?文件规定,所有屏幕上的控制器都必须同意自动旋转才能发生;如果该模式对话框中的屏幕上只有一个视图控制器设置为仅使用纵向,则它将仅以纵向显示。屏幕上唯一的其他控制器是模式对话框中包含的tableviewcontroller。它具有与shouldautorotate相同的样板代码。。。方法,但没有做到。我甚至在使用window.rootViewController,但仍然没有更改。