2
votes

This issue has crippled me for over a day. I need to modify the UINavigationBar's height.

The UINavigationController is created in the AppDelegate like so.

self.navigationController = [[UINavigationController alloc] initWithRootViewController:mainController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];

The height of the navbar WILL change and stick if I add [self.navigationController.navigationBar setFrame:newFrame] to viewDidAppear like the code below.

- (void)viewWilAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    CGRect newFrame = CGRectMake(0, 0, 320, 100);
    [self.navigationController.navigationBar setFrame:newFrame]
}

HOWEVER, if I do it this way, you can actually see the frame snapping from the original 44px to a 100px height in the split second that the view loads, which is very annoying.

I've tried adding the [navBar setFrame:] to viewDidload, viewWillAppear of the rootViewController and also the AppDelegate just after I initiate the UINavigationController. None of these work.

Just so you know, I've overridden the drawRect:(CGRect)rect method in a UINavigationBar category to make the background color solid black using the code below but I don't think that has something to do with the problem.

[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);

Does anyone know the best way to do this?

1

1 Answers

1
votes

"Use a toolbar instead of a navigation bar if you need to offer a larger set of controls, or you do not need to enable navigation." - From the iOS Human Interface Guidelines under Navigation Bar / Guidelines.