UINavigationController navigation bar will not shrink if in landscape mode

The navigation bar of the navigation controller does not change height when rotated to landscape. alt text

see that it stays at 44 pixels instead of 34, I think.

What can I do to fix this?

+3
source share
2 answers

You must add your navigation controller directly as a sub-view to your window, otherwise this will not work automatically. (There is no need to manually resize your navigation bar.)

-[application:didFinishLaunchingWithOptions:]Your method AppDelegateshould contain something like

[window addSubview:self.yourNavController.view];


, , XCode shouldAutorotateToInterfaceOrientation: RootViewController, YES.

+5

autoRotation navBar :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight))
    {
         self.navigationController.navigationBar.frame = CGRectMake(0,0,480,32);
    }
    else if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
    {
         self.navigationController.navigationBar.frame = CGRectMake(0,0,320,44);
    }
    else
    {
         assert(false);
    }
}
-1

Source: https://habr.com/ru/post/1784263/


All Articles