为什么导航会在视图中显示状态栏下方20个像素?

时间:2011-05-03 13:56:23

标签: iphone

  (void)viewDidLoad {

     [super viewDidLoad];

     UINavigationController *naviController = [[UINavigationController alloc]init];

     [self.view addSubview:naviController.view];
}   

如果我在视图中添加导航控制器,它会显示状态栏下方约20个像素。我希望它出现在状态栏下方。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

只需设置naviController.view的框架

naviController.view.frame = self.view.frame;

答案 1 :(得分:0)

在app delegate的UINavigationController

中声明applicationDidFinishLaunching:
UINavigationController *navController = [[UINavigationController alloc] init];

[navController pushViewController:viewControllerOfYourExample animated:YES];

答案 2 :(得分:0)

假设您将导航栏添加到0,0,那么看起来您的视图定位不正确。

简单的解决方法是将您的栏移动到0,-20

UINavigationController *naviController = [[UINavigationController alloc]init];
CGRect frame = [naviController frame];
frame.origin.y = -20;
[naviController setFrame:frame];
[self.view addSubview:naviController.view];

然而,这是一个黑客。

尝试这样的事情:

[[self view] setAutoresizesSubviews:YES];
UINavigationController *naviController = [[UINavigationController alloc]init];
[naviController setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin];
[self.view addSubview:naviController.view];

那可能有用吗?