PDA

View Full Version : Modal View Controller from Root View Controller in UISplitViewController




seepel
Aug 7, 2010, 11:08 AM
I am trying to present a modal view over my root view controller in a UISplitViewController app. Here is the relevant code.


modalViewController.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self.navigationController presentModalViewController:modalViewController.navigationController animated:YES];


This works fine when the app is in portrait orientation and the rootViewController is in a popover. And in landscape orientation it will work if the modalViewController has already been presented in portrait orientation. However, if I try to present the modal view controller for the first time in landscape orientation it will not display, and it seems as though the modal view picks up the wrong frame.

Anyone have any ideas?



PhoneyDeveloper
Aug 7, 2010, 11:51 AM
Apparently presenting modals from a popover isn't supported.

Hmmm. Maybe that's not relevant. Dunno.

seepel
Aug 7, 2010, 07:12 PM
Apparently presenting modals from a popover isn't supported.

Hmmm. Maybe that's not relevant. Dunno.

According to the documentation modal view controllers are supported for popovers with UIModalTransitionStyleCoverVertical which is what I'm using. It also works fine in the popover. In fact it only works reliably in the popover. If I present the controller in the popover, then present it again after rotating to landscape, it works fine. If I try to present it in landscape for the first time it won't show up. It seems like something gets set when I present it in portrait/in the popover, but for the life of me I can't figure out what it could be. Also, looking at the fram of the modal view it seems like it is picking up the frame that it would have in portrait, even though the device is in landscape.

seepel
Aug 11, 2010, 02:58 PM
Well, it probably isn't the most elegant or robust, and I'll probably have to clean it up later, but I have temporarily rolled my own modal view presentation with the following code. I'd still be very interested in getting this working the correct way, but for now I guess this will suffice.


- (void)presentManageViewController {
self.manageViewController.navigationController.view.frame = CGRectMake(self.navigationController.view.frame.origin.x,
self.navigationController.view.frame.origin.y+self.navigationController.view.frame.size.height,
self.navigationController.view.frame.size.width,
self.navigationController.view.frame.size.height);
[UIView beginAnimations:@"presentManageViewController" context:nil];
[UIView setAnimationDuration:0.3];
self.manageViewController.navigationController.view.frame = self.navigationController.view.frame;
[self.navigationController.view addSubview:self.manageViewController.navigationController.view];
[UIView commitAnimations];
}

- (void)dismissManageViewController {
[UIView beginAnimations:@"dismissManageViewController" context:nil];
[UIView setAnimationDuration:0.3];
self.manageViewController.navigationController.view.frame = CGRectMake(self.navigationController.view.frame.origin.x,
self.navigationController.view.frame.origin.y+self.navigationController.view.frame.size.height,
self.navigationController.view.frame.size.width,
self.navigationController.view.frame.size.height);
[UIView commitAnimations];
[self.manageViewController.navigationController.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.3];
}