Hi David -
David Restler wrote:
Question: What can I do in software (during the startup logic) to get the iPad to push my window down to make room for the status bar?
If you're creating the view in your code, you're explicitly setting the view frame. The controller then assumes you know what you're doing and doesn't make any adjustment for the status bar (or any other bars that may be above or below the content area).
In other words, when you explicitly set the frame in loadView, you're buying sole responsibility for the starting dimensions. In the case of an iPad with only the status bar, you need to drop the y-origin down 20, and shorten the height by 20:
- (void)loadView {
CGRect frame = CGRectMake(0, 20, 768, 1004);
UIView *v = [[UIView alloc] initWithFrame:frame];
self.view = v;
[v release];
NSLog(@"%s: self.view=%@ self.view.frame=%@",
_func_, self.view, NSStringFromCGRect(self.view.frame));
}
Btw, if you ever open your IB, try adding and subtracting the various simulated bars while watching the dimensions of the view in the Size Inspector. If the view is the main content view (i.e. connected to the 'view' outlet of File's Owner), you should see the y-origin and size adjust for each combination of bars. In fact, those dimensions will probably be grayed out, since IB doesn't trust us with such critical numbers. The point is, that when a view is loaded from a nib built with the correct simulated bars, the adjustment for the bars has already been saved in that file.
I think the iPad should do it automatically for me
If you want to see what the controller does by default (i.e. no nib and no frame defined in loadView), try this code:
// MyAppDelegate.m
#import "MyAppDelegate.h"
#import "MyViewController.h"
@implementation MyAppDelegate
@synthesize window, viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
MyViewController *vc = [[MyViewController alloc] initWithNibName:nil bundle:nil];
vc.view.backgroundColor = [UIColor grayColor];
self.viewController = vc;
[vc release];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
NSLog(@"%s: viewController.view.frame=%@",
_func_, NSStringFromCGRect(viewController.view.frame));
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
// MyViewController.m
#import "MyViewController.h"
@implementation MyViewController
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
@end
When no nib name is specified, and the view loader can't find a nib that matches the owner's class name, and loadView isn't overridden, the view controller creates a default view (see no. 3 under "The steps that occur during the load cycle are as follows:" in [Understanding the View Management Cycle|http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGf oriPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/doc/uid/TP 40007457-CH101-SW19] in the
View Controller Programming Guide for iOS). If you run the above example code, you should see the frame of the default view takes all bars into account.
... I'm using a coordinate of (0,0) for my upper left corner, which is correct
As explained above, it's not correct if there are any upper bars
and
after the first rotation everything works great.
Yes, all bets are off after an auto-rotation. The system recalculates the content view frame in that case (though that math doesn't always come out the way you want).
Hope that helps to unscramble things a little!
- Ray