Iphone UINavigationController';在横向模式下,导航栏不会收缩

Iphone UINavigationController';在横向模式下,导航栏不会收缩,iphone,uinavigationcontroller,uinavigationbar,landscape,Iphone,Uinavigationcontroller,Uinavigationbar,Landscape,当旋转到横向时,我的导航控制器的导航栏不会改变高度。 看,它保持在44像素,而不是我认为的34像素 如何解决此问题?在类的自动旋转方法中,按如下方式更改导航栏的框架: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if((self.interfaceOrientation == UIInterfaceOrientationLandscapeLe

当旋转到横向时,我的导航控制器的导航栏不会改变高度。

看,它保持在44像素,而不是我认为的34像素


如何解决此问题?

在类的自动旋转方法中,按如下方式更改导航栏的框架:

- (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);
    }
}

您必须将导航控制器直接作为子视图添加到窗口中,否则这不会自动工作。(无需手动更改导航栏的框架。)

-[application:didfishlaunchingwithoptions:
您的
AppDelegate
方法应该包含如下内容

[window addSubview:self.yourNavController.view];

要获得自动工作的示例,您还可以在XCode中创建一个新的基于导航的应用程序,并为总是返回YES的RootViewController的
shouldAutorotateToInterfaceOrientation:
方法添加一个实现