How to inform the parent viewcontroller about the changed screen orientation in the modal view controller?

无人久伴 提交于 2019-12-02 05:09:38

问题


I am presenting a modal view controller above a UISplitViewController while being in Portrait mode. Now I rotate the iPad to the Landscape mode and dismiss the modal view controller.

It seems that UISplitViewController didn't receive the notification about the changed orientation: The 1st view of the split view controller is hidden, and the view of the 2nd is not occupying the whole screen size.

If I rotate again back and forth, the split view controller is displayed normally again.

Moreover, the problem occurs only with the iOS Simulator 5.0 (or the device running iOS5) but not with the 4.3.

Any ideas?


回答1:


I'm having same problem.

In my project splitViewController is added as subview on window. And it receives rotation messages normally. But when I try to add my "modal" viewController as subview on window it does not receive rotation messages. Looks like rotation messages receive only subview at index 0. So I resolved it in this way:

Showing "modal" viewController

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

Hiding "modal" viewController

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

But there is one defect in this solution: a modalViewController will not load its view right after calling "[appDelegate.window insertSubview:myModalViewController.view atIndex:0]" method. To fix this defect I just present it as modal for a moment:

Showing "modal" 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];



回答2:


I´m having same problem here: Not working Orientation Notifications in VIewController under modal, with iOS5.

To call the method you want in the mainController you must use those magic lines in the modal, just in the method controlling rotating:

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

In i id, you have the same object you uses as: yourConfigurationOfController, in this case UISPlit, i think. If i, is not your uiSplit you can arrive by cascade of variables. interfaceOrientationReceived is the orientation received in the modal in:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Hope could help! Good luck!

(Apologize my English :))



来源:https://stackoverflow.com/questions/7767302/how-to-inform-the-parent-viewcontroller-about-the-changed-screen-orientation-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!