StatusBar is on the top navigation bar after MailComposer is fired

Problem: my status bar appears at the top of the navigationBar after I present it, and rejects MFMailComposerViewController as a modal view.

 -(IBAction)openMail:(id)sender { MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; mc.mailComposeDelegate = self; [mc setSubject:emailTitle]; [mc setMessageBody:messageBody isHTML:YES]; [mc setToRecipients:toRecipents]; [mc.navigationItem.leftBarButtonItem setTintColor:[UIColor colorWithRed:144/255.0f green:5/255.0f blue:5/255.0f alpha:1.0f]]; [self presentViewController:mc animated:YES completion:NULL]; } - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break; case MFMailComposeResultSaved: NSLog(@"Mail saved"); break; case MFMailComposeResultSent: NSLog(@"Mail sent"); break; case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@", [error localizedDescription]); break; default: break; } // Reset background image for navigation bars [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar.png"] forBarMetrics:UIBarMetricsDefault]; NSLog(@"%@",[GGStackPanel printFrameParams:self.view]); // Close the Mail Interface GGAppDelegate * appDel = [[UIApplication sharedApplication] delegate]; HHTabListController * contr = (HHTabListController*)appDel.viewController; [contr setWantsFullScreenLayout:NO]; NSLog(@"%i",[contr wantsFullScreenLayout]); [self dismissViewControllerAnimated:YES completion:NULL]; } 

There are a few similar questions about Stackoverflow, but none of the solutions suggested there work for me. I already tried:

Status bar and navigation bar error after rejected modal view

http://developer.appcelerator.com/question/120577/nav-bar-appears-underneath-status-bar

I tried to submit and remove from AppDelegate, without help.

Changing the viewing frame or navigation frame works, but I would have to do the same for all other views in my application (there are many of them). This will make my entire application addicted to this tiny bug.

Screenshots

View before presenting

After closing MailComposer:

View after dismissing

+4
source share
2 answers

wants FullScreenLayout is something complex and unrelated. ALL viewcontrollers are required in order to be built into the "layout view manager" (Apples UINavigationController, Apple UITabBarController), OR fully implement the complex logic "how much should I be and where do I position?". on their own.

Apple decided with iOS 1.0 that the main view of the iPhone that you see did NOT START at 0.0. The window that contains it starts with (0,0), but it appears above the status bar.

I think this decision, which they came to regret, it made sense at the time, but in the long run it caused a lot of mistakes.

Net effect:

  • UINavigationController and UITabBarController have a special (undocumented) internal code that makes it SEEM AS IF (0,0) the upper left corner - they force change / change any custom UIViewController that you add to them
  • ... if you DO NOT use one of them as the main controller, you will have to re-implement this logic yourself. If you use a third-party instance of the UIViewController, the logic often runs incorrectly or is missing.
  • ... you can fix it yourself at runtime by reinstalling UIViewController.view (its root view), for example. in the following way:

(code)

 UIViewController* rootController = // in this case HHTabController? UIView* rootView = rootController.view; CGRect frame = rootView.frame; CGPoint oldOrigin = frame.origin; CGPoint newOrigin = // calculate this, according to Apple docs. // in your current case, it should be: CGPointMake( 0, 20 ); frame.origin = newOrigin; frame.size = CGSizeMake( frame.size.width - (newOrigin.x - oldOrigin.x), frame.size.height - (newOrigin.y - oldOrigin.y) ); rootView.frame = frame; 

... obviously, it annoys having to do it every time. That's why Apple strongly recommends everyone to use the UINavigationController and / or UITabBarController :)

+3
source

This alternative solution is also very convenient to handle the strange behavior of the top layout guide, which repositions itself after the view controller is presented modally.

Add a constraint for the top span, not to the Top Layout Guide, but to the actual "view." Select the view (current distance ...) as shown in the screenshot below: enter image description here

Provided by: fooobar.com/questions/492863 / ...

0
source

All Articles