dismissModalViewController Hides the parent view behind status bar
Asked Answered
C

1

13

I have a very strange issue here. I am using a present modal view controller to display my MFMailComposer ViewController on top of a ViewController which is placed with in a Navigation Bar.

[self presentModalViewController:emailviewController animated:YES];

to hide , I use ...

-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{

    [self dismissModalViewControllerAnimated:YES];
}

Everything works fine but when I dismiss my MailComposer the original view controller hides behind the status bar .

I have tried to modify view offset by 10 using setFrame method but It din't worked . (this is tired before and after the modal view controller is presented and dismissed )

I have tried by hiding status bar temporarily but didn't worked.

I have tried self.navigationcontroller presentmodalviewcontrolle but that didn't worked too...

Any ideas or suggestions would be highly appreciated

After dismissmodalviewcontroller called

edited : Most of the people give me a suggestion to modify the offset manually. Well that does not work . Because if I do that in my viewDidLoad/viewWillapper of the original viewcontroller method then It shifts my view before the present modal view controller whereas after I load the modal view controller It becomes normal.

  • (void) viewDidAppear: (BOOL) animated { CGRect frame = self.navigationController.view.frame; frame.origin.y = 20; self.navigationController.view.frame = frame; }

Changing offset results in this

Cicely answered 21/6, 2012 at 0:49 Comment(16)
Does your original view controller have a status bar set to hidden or no?Tekla
nope .. I haven't touched the status bar yetCicely
So no status bar changes in the modal view controller as well as in the original view controller?Tekla
No. the status bar remains at the same place it's the viewcontroller behind the modal view controller changesCicely
Check in your IB file if you have Status Bar Gray or Black under simulated Metrics...Tekla
its Gray in my Navigation controllerCicely
Is the viewcontroller behind the modal the one that's calling dismissmodal?Pilliwinks
@Pilliwinks Yes. It's the view controller behind it is calling it . I have also tried using navigation controller the same thingCicely
Try to set frame to your viewcontroller instance and check in this way: CGRect l_RectFrame = [UIScreen mainScreen].applicationFrame; (OR) CGRect l_RectFrame = [UIScreen mainScreen].bounds;Caryl
Refer to these links too: #1871689 #2145002Caryl
@Caryl thanks that was quite helpful ... to narrow down the problem but I still have that issue ... What is happening is that my original view which invoked the modal view is shifted behind the status bar. The viewcontroller which is presented using presentModalviewcontroller is displayed correctly .Cicely
I am not able to modify the original viewcontrollers offset because its already been loaded .. I dont know what to do nextCicely
Have you checked the frame and the bounds of the viewController behind the modal view controller?Saurischian
yes ... it its 320 460 with 20 for status bar ..Cicely
Ok. My Problem is fixed but I dont know how. My Navigation Controller was initially intialized by self.navigationController setViewControllers: Array of View controller . In one of them I had disabled auto rotation by sending shouldAutorotateTo.... to return as NO whereas in others it was YES . I changed that one to comply with others and it worked. I dont have any idea whats going on but . I will simulate this and file a bug for Apple unless any one else could help me to figure out whats going on under the hoodCicely
Sounds like a bug. But where were you calling your modal from? Were you doing anything with the window before or after you called your modal? That can cause strange things like what you experience to happen.Meliorism
P
3

Try putting this in ViewDidAppear:

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

Worst case, if it is always happening only after the modal view controller is dismissed, declare a boolean for afterFirstLaunch in the .h and put this in viewDidAppear:

if(afterFirstLaunch){
      CGRect frame = self.navigationController.view.frame;
      frame.origin.y = 20;
      self.navigationController.view.frame = frame;
}
else {
      afterFirstLaunch = true;
 }
Phyllisphylloclade answered 21/7, 2012 at 6:31 Comment(3)
If that doesn't work, posting code might help. Are both views made using Interface Builder? How are you presenting the modal view controller?Phyllisphylloclade
It seems to me that shifting the view frame after the view has all ready appeared is going to look very nasty. The view should be properly positioned before it appears.Pettish
It depends on how you are presenting the view. If it is presented with a transition animation, then yes, it will look weird at first. However, if the view just appears without any animation, the difference will imperceptible.Phyllisphylloclade

© 2022 - 2024 — McMap. All rights reserved.