如何通知父视图控制器有关模态视图控制器中更改的屏幕方向?

时间:2011-10-14 12:03:04

标签: ios rotation uisplitviewcontroller modalviewcontroller ios5

我在纵向模式下呈现UISplitViewController上方的模态视图控制器。现在我将iPad旋转到横向模式并关闭模态视图控制器。

似乎UISplitViewController没有收到有关更改方向的通知: 分割视图控制器的第一个视图被隐藏,第二个视图不占用整个屏幕尺寸。

如果我来回再次旋转,分割视图控制器会再次正常显示。

此外,问题仅出现在iOS模拟器5.0(或运行iOS5的设备)上,而不是4.3中。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题。

在我的项目中,splitViewController被添加为窗口上的子视图。它通常会收到轮换消息。但是当我尝试在窗口上添加我的“模态”viewController作为子视图时,它不会收到旋转消息。看起来旋转消息只接收索引0处的子视图。所以我以这种方式解决了它:

显示“模态”viewController

[appDelegate.window insertSubview:myModalViewController.view atIndex:0];
[appDelegate.splitViewController.view removeFromSuperview];

隐藏“modal”viewController

[appDelegate.window insertSubview:appDelegate.splitViewController.view atIndex:0];
[myModalViewController.view removeFromSuperview];

但是此解决方案中存在一个缺陷:modalViewController在调用“[appDelegate.window insertSubview:myModalViewController.view atIndex:0]”方法后不会立即加载其视图。为了解决这个缺陷,我暂时将其作为模态提出:

显示“模态”viewController:

// present and dismiss methods are called to cause viewDidLoad in modalViewController
[appDelegate.splitViewController presentModalViewController:myModalViewController animated:NO];
[appDelegate.splitViewController dismissModalViewControllerAnimated:NO];

[appDelegate.window insertSubview:myModalViewController.view atIndex:0];
[appDelegate.splitViewController.view removeFromSuperview];

答案 1 :(得分:0)

我在这里遇到同样的问题:Not working Orientation Notifications in VIewController under modal, with iOS5

要在mainController中调用所需的方法,您必须在模态中使用这些魔术线,只需在控制旋转的方法中使用:

yourProjectAppDelegate *delegate = (yourProjectAppDelegate*) [[UIApplication sharedApplication]delegate];
yourProjectViewController *i=((yourProjectViewController *)delegate.window.yourConfigurationOfController);
[i didRotateFromInterfaceOrientation:interfaceOrientationReceived];

在i id中,你使用的对象是:yourConfigurationOfController,在这种情况下是UISPlit,我想。如果我,不是你的uiSplit,你可以通过级联变量到达。 interfaceOrientationReceived是模式中收到的方向:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

希望可以帮助! 祝你好运!

(道歉我的英文:))