我正在尝试获得正确的内容框架大小,它考虑了导航栏的高度大小。
但是如果在 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