I’m trying to get correct content frame size which considered the navigationbar’s height size.
But if output frame size using NSLog in willRotateTo~ method, shows earlier frame size.
However it shows correct frame size in didRotateFrom~ method.
How to get the frame size like didRotateFrom~ ‘s size in willRotateTo~ method?
Following is AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
ViewController *rootView = [[[ViewController alloc] init] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootView] autorelease];
} else {
self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootView] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
And next is ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"willRotate size is width : %f height : %f", self.view.frame.size.width, self.view.frame.size.height);
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
NSLog(@"didRotate size is width : %f height : %f", self.view.frame.size.width, self.view.frame.size.height);
}
Following is result when rotated to landscape.

/Users/nice7285/Library/Caches/appCode10/DerivedData/testView-d007adbb/Build/Products/Debug-iphonesimulator/testView.app/testView
Simulator session started with process 3896
2012-10-11 04:28:59.719 testView[3896:11303] willRotate size is width : 320.000000 height : 416.000000
2012-10-11 04:29:00.025 testView[3896:11303] didRotate size is width : 480.000000 height : 268.000000
The reason
self.view.frameinwillRotateToInterfaceOrientationis giving you the dimensions before rotation is because the view has not been rotated yet, so the the frame has not been changed yet. The only thing you can know at that point is what orientation you are rotating to. If you want the new dimensions in that function you’ll have to hardcode them in yourself. You shouldn’t need to do this though asdidRotateFromInterfaceOrientationshould be able to do everything you want.