当我设置它时,这看起来很简单,但我无法解释为什么状态栏和导航栏之间存在这种差距。此外,所包含的视图看起来可能是正确对齐的,只是导航栏向下移动。差距看起来像状态栏的大小,所以我想这与它有关,但我不知道是什么。

下面是设置导航控制器的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
advancedVC = [[AdvancedSearchFormVC alloc] initWithNibName:@"AdvancedSearchForm" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:advancedVC];
nav.navigationBar.tintColor = [UIColor defaultNavBarTint];
nav.navigationBar.topItem.title = NSLocalizedString(@"SearchTitle", nil);
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"SearchButton", nil) style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList:)];
nav.navigationBar.topItem.rightBarButtonItem = searchButton;
self.view = nav.view;
}rootViewController使用来自xib文件的视图,我在该文件中模拟了状态栏、导航栏和选项卡栏。
发布于 2013-02-18 20:26:10
正如我们现在所知道的,20像素的偏移是为了给顶部的状态栏提供空间。但实际上,视图控制器坐标系保持不变,只有导航栏框架向下移动了20个像素。这使得导航栏实际上与视图的顶部20个像素重叠。
记录导航栏框架原点,它将显示(0.0,20.0)
因此,解决方案是在ViewWillAppear中将导航栏的原点重新定位为(0.0,0.0)。
self.navigationController.navigationBar.frame = CGRectMake(0.0, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);https://stackoverflow.com/questions/8873695
复制相似问题