开发者

Why do navigation appear 20 pixels below status bar in the view?

开发者 https://www.devze.com 2023-03-02 03:58 出处:网络
(void)viewDidLoad { [super viewDidLoad]; UINavigationController *naviController = [[UINavigationController alloc]init];
  (void)viewDidLoad {

     [super viewDidLoad];

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

     [self.view addSubview:naviController.view];
}   
开发者_运维技巧

If I add navigation controller in the view, it appears about 20 pixels below status bar. I want it appears just below status bar. How do I fix this?


Just set the frame for naviController.view

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


Assuming that you're adding your navigation bar at 0,0 then it looks like you're view isn't positioning correctly.

The easy fix is to move your bar to be at 0,-20

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

However, that's a hack.

Try something like this instead :

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

That might work?


DeclareUINavigationController in the app delegate's applicationDidFinishLaunching:

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

[navController pushViewController:viewControllerOfYourExample animated:YES];

0

精彩评论

暂无评论...
验证码 换一张
取 消