开发者

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

开发者 https://www.devze.com 2023-04-12 20:13 出处:网络
I am presenting a modal view controller above a U开发者_如何转开发ISplitViewController while being in Portrait mode. Now I rotate the iPad to the Landscape mode and dismiss the modal view controller.

I am presenting a modal view controller above a U开发者_如何转开发ISplitViewController 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?


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


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 :))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号