Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

seepel

macrumors 6502
Original poster
Dec 22, 2009
471
1
I am trying to present a modal view over my root view controller in a UISplitViewController app. Here is the relevant code.

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

macrumors 68040
Sep 2, 2008
3,114
93
Apparently presenting modals from a popover isn't supported.

Hmmm. Maybe that's not relevant. Dunno.
 

seepel

macrumors 6502
Original poster
Dec 22, 2009
471
1
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

macrumors 6502
Original poster
Dec 22, 2009
471
1
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.

Code:
- (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];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.