TheTC
TheTC

Reputation: 697

uinavigationbar moves up when returning from inactive state

I have a custom image header ABOVE the uinavigationbar. I do this with this code:

self.navController.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0); 
self.navController.navigationBar.frame = CGRectMake(0.0, 73.0, 320.0, 44.0);

UIView *checkNav = [self.navController.view viewWithTag:9999];
if (checkNav == nil) {
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header-logo.jpg"]];
    imgView.tag = 9999;
    [imgView setFrame:CGRectMake(0.0, 23.0, 320.0, 50.0)];
    [self.navController.view addSubview:imgView];
}

This works great. But, when the app goes inactive (hit the main iphone home button) and then you go back into the app, the uinavigationbar shifts up to the default place at the top of the screen and is hidden behind my custom header image.

I've tried throwing code into applicationDidBecomeActive, but it doesn't help. Any help would be greatly appreciated.

Thanks!

Upvotes: 1

Views: 770

Answers (2)

jrturton
jrturton

Reputation: 119242

You do get warned about this in the docs:

With only a few exceptions, you should never modify the navigation bar object directly. It is permissible to modify the barStyle or translucent properties of the navigation bar but you must never change its frame, bounds, or alpha values directly

Having said that, you should be able to get the effect by repeating your above code in applicationDidBecomeActive or applicationWillEnterForeground, assuming you have a pointer to the navigation controller from there. You may find that hiding and re-showing the navigation bar is required (bit of a hack, but it can help - I had a similar problem with hiding / showing the status bar and the navigation bar not going to its correct place)

Upvotes: 2

simongking
simongking

Reputation: 740

What about putting the code into viewWillAppear?

Upvotes: 0

Related Questions