Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After dismissModalViewControllerAnimated the parent view is set to fullscreen

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.

like image 345
Raphael Avatar asked Dec 05 '22 01:12

Raphael


2 Answers

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.

like image 190
imaginaryboy Avatar answered Jan 25 '23 23:01

imaginaryboy


Something that works for me was to restore the frame after the modal view controller is dismissed. Code example:

Presenting Modal View Controller

[self presentModalViewController:self.modalViewController animated:YES];

Dismissing Modal View Controller

CGRect frame = self.view.frame;
[self.modalViewController dismissModalViewControllerAnimated:YES];
self.view.frame = frame;
like image 30
Samu Avatar answered Jan 26 '23 00:01

Samu