Search code examples
iosobjective-cuiwindowappdelegate

Why is height of window 480 when applicationFrame height is 460?


I create a TabBar VC in my AppDelegate class, setting the window frame by [[UIScreen mainScreen] bounds]. Since I have a status bar displayed the height should be 460, but it appears to be 480. If I set the height manually to be 460 it cuts of touch recognition to the bottom part of the tabs. Below is the code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIColor *brownNavBarColor = [[UIColor alloc] initWithRed:0.78f green:0.56f blue:0.06f alpha:1.0f];
[application setStatusBarHidden:NO];

CGRect windowRect = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:windowRect];

CGRect appFrame = [[UIScreen mainScreen] applicationFrame];

NSLog(@" appFrame %f", appFrame.origin.y);
NSLog(@" appFrame %f", appFrame.size.height);

NSLog(@" window.frame %f", self.window.frame.origin.y);
NSLog(@" window.frame %f", self.window.frame.size.height);

NSLog(@" window.bounds %f", self.window.bounds.origin.y);
NSLog(@" window.bounds %f", self.window.bounds.size.height);

[self.window makeKeyAndVisible];

self.ingredientTabVC2 = [[NewIngredientViewController alloc] initWithNibName:nil bundle:NULL];
self.ingredientNC2 = [[UINavigationController alloc] initWithRootViewController:self.ingredientTabVC2];
[self.ingredientNC2.navigationBar setTintColor:brownNavBarColor];

self.ingredientTabVC3 = [[IngredientTabViewController alloc] initWithNibName:nil bundle:NULL];
self.ingredientNC3 = [[UINavigationController alloc] initWithRootViewController:self.ingredientTabVC3];
[self.ingredientNC3.navigationBar setTintColor:brownNavBarColor];

self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:NULL];
self.tabBarController.viewControllers = [[NSArray alloc] initWithObjects: self.ingredientNC2, self.ingredientNC3, nil];


[self.window setRootViewController:self.tabBarController];
return YES;
}

This gives log output

2013-02-12 23:04:21.867 SingleTest[24221:c07]  appFrame 20.000000
2013-02-12 23:04:21.868 SingleTest[24221:c07]  appFrame 460.000000
2013-02-12 23:04:21.869 SingleTest[24221:c07]  window.frame 0.000000
2013-02-12 23:04:21.870 SingleTest[24221:c07]  window.frame 480.000000
2013-02-12 23:04:21.870 SingleTest[24221:c07]  window.bounds 0.000000
2013-02-12 23:04:21.871 SingleTest[24221:c07]  window.bounds 480.000000

Can someone explain the reason behind this difference?


Solution

  • From the docs for UIScreen:

    applicationFrame:

    This property contains the screen bounds minus the area occupied by the status bar, if it is visible. Using this property is the recommended way to retrieve your application’s initial window size. The rectangle is specified in points.

    bounds:

    Contains the bounding rectangle of the screen, measured in points. (read-only)

    bounds includes the status bar, applicationFrame doesn't.

    Notice too that the applicationFrame has a y origin of 20.

    You want the main window to fill the screen. When you set the window's rootViewController, it will be adjusted to the applicationFrame automatically.