Mia
Mia

Reputation: 145

Navigationbar position reset when turn back to foreground

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 .

Upvotes: 3

Views: 557

Answers (2)

Mia
Mia

Reputation: 145

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.

Upvotes: 0

Mahmoud Adam
Mahmoud Adam

Reputation: 5852

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:];

Upvotes: 1

Related Questions