【问题标题】:UINavigationController's navigation bar wont shrink when in Landscape modeUINavigationController 导航栏在横向模式下不会缩小
【发布时间】:2011-01-08 14:56:07
【问题描述】:

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

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

我该怎么做才能解决这个问题?

【问题讨论】:

    标签: iphone uinavigationcontroller uinavigationbar landscape


    【解决方案1】:

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

    AppDelegate-[application:didFinishLaunchingWithOptions:] 方法应包含类似

    的内容
    [window addSubview:self.yourNavController.view];
    


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

    【讨论】:

      【解决方案2】:

      在你的类的 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);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-19
        • 2011-09-10
        • 2014-09-06
        • 1970-01-01
        相关资源
        最近更新 更多