Navbar position reset when rotated to front

I have set my navbar to my first ViewContoller in viewWillAppear

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

      

This allowed me to put the logo above the panel.

But when I go back to the background and go back, the position of the navbar is reset to the top.

I tried addObserver which caught UIApplicationWillEnterForegroundNotification

and set the navbar border again. But it doesn't work.

Please help, Thanks a lot.

+3


source to share


2 answers


you can try to change the look NavigationBar

and it will display the whole application

[[UINavigationBar appearance] setFrame:];

      



and you can change its background image if you like

[[UINavigationBar appearance] setBackgroundImage:forBarMetrics:];

      

+1


source


I found a solution.

  • Subclass of UINavigationBar.

  • implement a method - (CGSize)sizeThatFits:(CGSize)size

    to resize the navigation bar.

such as



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

      

It works great.

0


source







All Articles