iPad Modal View旋转parentViewController查看
当应用程序处于横向模式(我打算强制执行)时,显示模式视图会导致父视图旋转到纵向模式。如果将shouldAutoRotateToInterfaceOrientation的返回值设置为NO,则父代不会旋转,但是模式会从侧面滑入并侧向显示。下面是揭示模态的代码。iPad Modal View旋转parentViewController查看
- (IBAction)loadExistingGame:(id)sender {
SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
savedGames.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:savedGames animated:YES];
[savedGames release];
}
根据要求在这里是的SavedGamesTableViewController
- (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;
}
模态的ViewController应为相同的方法返回NO。
的shouldAutoRotate方法的基于
当应用程序的内容在土地上(,我打算强制), 显示模态视图导致 父视图旋转到肖像 模式。
和
根据要求这里是 的 SavedGamesTableViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
的shouldAutoRotate方法的内容,那么你的意思是,父视图控制器尚未设置为仅强制使用横向方向,并且当您显示设置为允许所有方向的模式视图时,您就是w当您将设备旋转至肖像时,为什么您的父视图旋转为纵向?我不明白你的问题......你是不是说父视图控制器当前设置为允许旋转为纵向?这不正是应该发生的事情吗?
没有设备没有被旋转。显示模态视图时,模态的父对象会旋转。 – Kyle 2010-09-20 14:20:25
除了'SavedGamesTableViewController'外,还有另一个控制器在屏幕上显示吗?该文档指出,所有屏幕上的控制器都必须就其发生的自动旋转达成一致;如果该模式对话框中的屏幕上只有一个视图控制器设置为仅使用肖像,则只能以肖像显示。 – 2010-09-20 16:36:49
屏幕上唯一的其他控制器是模态中包含的tableviewcontroller。它具有与shouldautorotate ...方法相同的样板代码。 – Kyle 2010-09-20 17:30:09
我在调出模态邮件视图时遇到类似问题。强制旋转不适用于我,但在应用程序的主视图控制器而不是子视图控制器上调用presentModalViewController可解决此问题。
没有办法。我甚至使用window.rootViewController,但仍然没有改变。 – stigi 2011-05-05 15:09:32
我看到了相同的行为;在我的情况下,问题是我已经实现了shouldAutorotateToInterfaceOrientation无条件为父视图控制器返回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的我继承UINavigationController的,就像这样:
@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController
@end
@implementation MyCustomNavigationControllerSupportingAllOrientations
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
请出示的'内SavedGamesTableViewController shouldAutoRotateToInterfaceOrientation'实施。 – 2010-09-20 02:17:52
增加了方法,但它只是锅炉板生成的代码。 – Kyle 2010-09-20 02:56:05