ナビゲーションバーの高さサイズを考慮した正しいコンテンツフレームサイズを取得しようとしています。
ただし、willRotateTo〜メソッドでNSLogを使用してフレームサイズを出力すると、以前のフレームサイズが表示されます。
ただし、didRotateFrom〜メソッドで正しいフレームサイズが表示されます。
willRotateTo〜メソッドでdidRotateFrom〜のサイズのようなフレームサイズを取得するにはどうすればよいですか?
以下は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;
}
そして次は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);
}
横向きに回転させた場合の結果は以下のとおりです。
/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