2

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

- (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;

}

4

5 回答 5

2

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

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

}

模态视图控制器应该为相同的方法返回 NO。

于 2010-09-22T22:44:04.220 回答
0

基于

当应用程序处于横向模式(我打算强制)时,显示模态视图会导致父视图旋转到纵向模式。

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

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

所以你说的是父视图控制器还没有设置为强制只使用横向,当你显示一个设置为允许所有方向的模态视图时,你想知道为什么你的父视图旋转到纵向时您将设备旋转到纵向?我不明白你的问题......你不是说父视图控制器当前设置为允许旋转到纵向吗?这种行为不正是应该发生的吗?

于 2010-09-20T06:37:37.503 回答
0

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

于 2011-04-29T20:31:36.373 回答
0

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

于 2012-02-26T07:41:37.383 回答
0
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 之前,我将 UINavigationController 子类化,如下所示:

@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController
@end

@implementation MyCustomNavigationControllerSupportingAllOrientations
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end
于 2013-04-02T08:41:25.443 回答