【问题标题】:iPhone: Weird space at the top of UINavigationControlleriPhone:UINavigationController 顶部的奇怪空间
【发布时间】:2010-11-05 16:16:54
【问题描述】:

我在将 UINavigationController 添加到我的 iPhone 应用程序时遇到了一个奇怪的问题。我添加控制器如下:

myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];

myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];

UIView *finalView = myeNavigationViewController.view;

[self.view addSubview:finalView];

一切似乎都按计划进行,只是在状态栏和 UINavigationController 标题栏之间的视图顶部出现了一个奇怪的空白。 alt text http://www.andrewskinner.name/problem.png

我在网上搜索过,但不知道要搜索什么。有没有其他人有这个问题?你能给我指明一些帮助的方向吗?

提前致谢。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uinavigationcontroller


    【解决方案1】:

    也许你以某种方式得到了两个 UIView, 每个都有一个状态栏。检查xib。

    【讨论】:

      【解决方案2】:

      行是什么

      UIView *finalView = myeNavigationViewController.view;
      

      添加到代码中?这是多余的,因为您可以直接添加视图而无需先将其分配给 UIView - 而且它不正确,因为它引用了 myNavigationController 而不是 navigationController..
      我倾向于这样做

      myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];    
      myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];
      [navigationController.view setFrame: [self.view bounds]];
      navigationController.delegate = self;
      [self.view addSubview:[navigationController view]];
      

      将框架设置为边界也会删除您所询问的顶部的空白。

      【讨论】:

        【解决方案3】:

        【讨论】:

          【解决方案4】:

          问题是 UINavigationController 理想情况下应该是 UIWindow 的直接子视图。它会自行定位和调整大小。当您将 UINavigationController 添加到 UIWindow 子视图的另一个自定义视图中时,您需要通过考虑状态栏是否显示在 UIWindow 中来处理此自定义视图的位置和大小。

          我的建议是将自定义视图作为 UINavigationController 的子类:

          mySubClass_NavigationController*nav=[[mySubClass_NavigationController alloc] initWithRootViewController:viewController ];
          
          [myUIWindow addSubview:nav.view];
          

          在 mySubClass_NavigationController 中,您可以在自己中进行所有自定义(无论该控制器是什么)。

          【讨论】:

            【解决方案5】:

            我也为此苦苦挣扎了一段时间,使用与操作非常相似的代码,并且在我的导航控制器上方还有一个白条。

            在将 UINavigationController 添加为 UITabController 中的视图时出现了问题。在我的例子中,空间是由 UINavigationController 的 UINavigationBar 部分引起的,考虑到状态栏,它实际上是我试图在 UINavigationController 中显示的视图的重叠部分。

            这是我最终在我的 UITabBarController 视图控制器之一的 loadView 中使用的代码。

            SomeUITableViewController *screenList = [[SomeUITableViewController alloc] init];
            
            UINavigationController *navController = [[UINavigationController alloc]
                                                     initWithRootViewController:screenList];
            
            CGRect frame = [[navController navigationBar] frame];
            
            frame.origin.y = 0; // Was 20, set to 0 to not take into account the status bar.
            
            [[navController navigationBar] setFrame:frame];
            
            [self setView:[navController view]];
            

            http://discussions.apple.com/message.jspa?messageID=7890362 有更多信息。

            【讨论】:

              【解决方案6】:

              IB 中有一个名为“Hides Bottom Bar on Push”的晦涩属性。只是检查一下。它为我解决了这个问题。

              【讨论】:

                猜你喜欢
                • 2015-02-10
                • 1970-01-01
                • 2011-11-27
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多