我navigationBar
在父视图控制器中显示:
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[super viewWillDisappear:animated];
}
然后,在下一个视图控制器中
- (void)viewDidLoad
{
/* ... */
NSLog(@"%i, %g", self.navigationController.navigationBarHidden,
self.view.frame.size.height);
}
- (void)viewWillAppear:(BOOL)animated
{
/* ... */
[super viewWillAppear:animated];
NSLog(@"%i, %g", self.navigationController.navigationBarHidden,
self.view.frame.size.height);
}
- (void)viewWillLayoutSubviews
{
NSLog(@"%i, %g", self.navigationController.navigationBarHidden,
self.view.frame.size.height);
}
- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"%i, %g", self.navigationController.navigationBarHidden,
self.view.frame.size.height);
}
输出:
-[viewDidLoad]: 1, 416
-[viewWillAppear:]: 0, 460
-[viewWillLayoutSubviews]: 0, 416
-[viewDidAppear:]: 0, 416
如您所见viewWillAppear
,出错了self.view.frame.size.height
。可以用viewWillLayoutSubviews
,不过是iOS5引入的。是否可以在 viewWillAppear 中获得正确的帧高度?