Possible Duplicate:
“Incorrect” frame / window size after re-orientation in iPhone
I'm trying to solve a very frustrating issue with an app of mine - in studying it I may have found a bug in iOS:
When you rotate the iPad, the view rotates, but it's frame does not change. I am running a timer that prints out the width and height of my view every second, and although I can see the view rotate visually, the frame remains "768x1024" no matter what.
From Apple's docs:
When the user interface rotates, the window is resized to match the new orientation. The window adjusts the frame of its root view controller to match the new size, and this size in turn is propagated down the view hierarchy to other views.
This is exactly what isn't happening, and it's causing me all sorts of trouble. Does anyone know how to fix rotation so that the frame changes?
Steps to reproduce:
- Create a new empty project
- Add a bone stock UIViewController as the root view
- Set a timer to print out the root view controller's frame width and height
- Run your app, and rotate it all around. Here's my code I'm testing with:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[UIViewController alloc] init]; NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height); // Add a label to confirm orientation UILabel *orientationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,30)]; orientationLabel.text = @"Top Left"; [self.window.rootViewController.view addSubview: orientationLabel]; [NSTimer scheduledTimerWithTimeInterval:.3 target:self selector:@selector(testScale) userInfo:nil repeats:YES]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
- (void) testScale { NSLog(@"%fx%f", self.window.rootViewController.view.frame.size.width, self.window.rootViewController.view.frame.size.height); }