Navigationbar position reset when turn back to foreground

567 Views Asked by At

I set my navigation bar in my first ViewContoller at viewWillAppear

self.navigationController.navigationBar.frame = CGRectMake(0.0, 64.0, self.navigationController.view.bounds.size.width, 44.0);

It let me put a logo above the bar .

But when I turn the app to background and turn back , the navigationbar position reset to the top .

I have tried addObserver that catchUIApplicationWillEnterForegroundNotification and set the frame of navigationbar again . But it's not working .

Please help , thanks a lot .

2

There are 2 best solutions below

0
On BEST ANSWER

I had found the solution.

  1. Subclass UINavigationBar.

  2. implement the - (CGSize)sizeThatFits:(CGSize)size method to change navigation bar size.

such as

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = self.window.bounds.size ;
    newSize.height = 91;
    return newSize;
}

It works perfect.

1
On

you can try to change the appearance of the NavigationBar and it will reflect allover the app

[[UINavigationBar appearance] setFrame:];

and you can change its background image if you want

[[UINavigationBar appearance] setBackgroundImage:forBarMetrics:];