IPhone - After dismissing Modal View Controller - gap is left at top of page
Solution 1
Turns out this was happening because I was calling my modalviewcontroller on the current view controller, but my view controller already had a another view controller loaded as a subview. Once I changed it to make the view controller in the subview, load the modal, then it went away. Thanks for all your help.
Solution 2
I had the same problem. My solution was to temporarily close the status bar just before switching views:
- (void) temporarilyHideStatusBar {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self performSelector:@selector(showStatusBar) withObject:nil afterDelay:0];
}
- (void) showStatusBar {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
// Use these by calling the hide function just before a broken view switch:
[self temporarilyHideStatusBar];
[self doViewSwitch];
// No need to call [self showStatusBar]; explicitly.
I experimented with other code-based solutions, and I like this one the best because it works 100% of the time - some of my frame-based solutions only worked most of the time - and because it has minimal user-visible effects.
I suspect this is an Apple bug, and it would be nice to hear the official word from them on the best workaround.
Solution 3
I ran into the same issue. Not sure what causes it, but I fixed it with the following line of code just after I dismiss my modal view:
[self.view setFrame:CGRectMake(0, 10, self.view.frame.size.width, self.view.frame.size.height)];
Just adjust the Y offset to meet your needs. In another instance I had to make it 20 instead of 10.
Solution 4
Just wanted to chime and say I had the exact opposite problem - a white gap at the bottom of the screen. And the fix was also the opposite, I was presenting from a subview, when I needed to be presenting from the parent. Thanks!
Solution 5
In case anyone looks at this post (I did today and so others might). I am a newbie to objective c but and you may laugh at my suggestion but here goes.
When running my iPad app the status bar was always overlapping my form. I wasn't happy to use the method for changing the frame coordinate down 20px so went searching.
Found that if I was to assign my custom view controller to the window rootViewController then the status bar overlap problem went away. I haven't tried the modal stuff in this post but hope this helps other newbies who may be wondering how to sole this problem.
This is what a simple AppDelegate didFinishLaunchingWithOptions method would look like:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
TEGGameViewController *gameVC = [[TEGGameViewController alloc] init];
self.window.rootViewController = gameVC;
[self.window makeKeyAndVisible];
return YES;
}
Brian
Updated on July 29, 2022Comments
-
Brian almost 2 years
When starting the app, if the user doesn't have login information stored, I want to display a modal view controller to force the entry of this information. I found through trial and error, that this had to occur in viewDidAppear of my root view controller. I tried to put it in viewDidLoad and viewWillAppear, but those didn't work unless I assigned the view of the root view controller to the view of the navigation controller used in the modal which then caused other issues...
So I have:
- (void)viewDidAppear:(BOOL)animated { NewAccountViewController *newAccountViewController = [[[NewAccountViewController alloc] initWithNibName:@"NewAccountViewController" bundle:nil] autorelease]; UINavigationController *accountNavigationController = [[UINavigationController alloc] initWithRootViewController:newAccountViewController]; [self presentModalViewController:accountNavigationController animated:YES]; }
And in the newAccountViewController I have a simple navigation item button that dismisses the modal view controller with dismissModalViewController.
This all works and when the modal is dismissed a view in a navigation controller is visible with its navigation item title at the top....
But there is a white gap about the same size as the status bar between the status bar and the top of the blue navigation item bar. If I don't do the modal, then the gap is never there. It only occurs after the modal is presented and dismissed. I've tried doing animated:NO on both the present and dismissModalViewController. I've also tried not using the navigation controller in the modal, and that did nothing as well. Any ideas would be great! Thanks.