After every dismiss off a ModalViewController the parent view is set to fullscreen. Why?
Before After
+----------------+ +------------------+
|head | | detailview |
+----------------+ | |
|detailview | | |
| | | |
| | | |
| | | |
+----------------+ +------------------+
I created a "simple" sample project where the error appear.
http://github.com/rphl/modalTest
Please take a look at it.
This is somewhat of a guess, but an educated guess after having played around with your code a bit.
When you present a modal view it is added as a subview of the view belonging to the controller on which presentModalViewController
was called. Since the modal view is intended to be displayed full screen it would appear as though internally the frame of the superview is being made full screen.
I put the following in your MyDetailViewController:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = self.navigationController.view.frame;
NSLog(@"%@", NSStringFromCGRect(frame));
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
CGRect frame = self.navigationController.view.frame;
NSLog(@"%@", NSStringFromCGRect(frame));
}
Which resulted in the following output:
2010-09-19 00:23:51.823 ModalTest[2478:207] {{0, 164}, {320, 316}}
2010-09-19 00:23:56.178 ModalTest[2478:207] {{0, 0}, {320, 480}}
The first line was output when the detail first appeared. The second line was output when the modal view was dismissed.
Now I actually don't particularly like the solution I found, but this has the desired affect. In your sendMail
method:
ModalTestAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.viewController presentModalViewController:controller animated:YES];
And in your mailComposeController:didFinishWithResulterror:
method:
ModalTestAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.viewController dismissModalViewControllerAnimated:YES];
Basically this has the effect of making sure it's the full screen view holding the main UI of your application that presents the full screen modal view. I don't think it's ideal however because I'm not a huge fan of deep parts of the code reaching up into the app delegate like that.
Something that works for me was to restore the frame after the modal view controller is dismissed. Code example:
[self presentModalViewController:self.modalViewController animated:YES];
CGRect frame = self.view.frame;
[self.modalViewController dismissModalViewControllerAnimated:YES];
self.view.frame = frame;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With