There are a few questions already on this, but none with a satisfactory answer. I'd like to know exactly why the frame and bounds appear to be wrong, using the simplest possible example, and for someone to tell me what the proper way to deal with it is...
I make a single view application, without a storyboard, and i tick support for landscape only. Then in didFinishLaunching method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
and in the view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"%.1f,%.1f",self.view.frame.size.width,self.view.frame.size.height);
}
Then the output is 768.0,1024.0 - which is obviously wrong, even though the red color has filled the landscape size screen. So I can't rely on the self.view.frame or self.view.bounds to arrange or resize subviews.
What is the most up to date and "proper" way to avoid problems like this? (without using nibs or storyboards, and without hacky swapping of width and height)