如何隐藏/禁用第一个uinavigationbar? [英] How to hide/disable only the first uinavigationbar?

查看:136
本文介绍了如何隐藏/禁用第一个uinavigationbar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在徘徊如何隐藏/删除/禁用导航控制器中的主要或第一个导航栏,以便我可以将图像作为整个背景屏幕,但我找不到任何解决方案。

I've been wandering how to hide / remove / disable only the main or first navigation bar in the navigation controller so that I could put an image as a whole background screen but I couldn't find any solution.

尝试隐藏主导航控制器的viewdidLoad中的titleview但是没有用。尝试使用navigationBarHidden,但它隐藏了下一堆控制器的整个导航栏。

Did try hide the titleview in viewdidLoad of the main navigation controller but didn't work. Tried using navigationBarHidden but it hides the whole navigation bar for the next stack of controller.

所以,我不知道该怎么做。举个例子,我希望有类似这样的应用程序 - 大师赛高尔夫锦标赛 - http://appshopper.com/sports/the-masters-golf-tournament

So, I'm not sure how to do this. To give you an example, I would like to have something like this app - The Masters Golf Tournament - http://appshopper.com/sports/the-masters-golf-tournament.

如果你看一下屏幕1,它没有任何顶部的导航栏,但当您触摸任何选项时,它将推送到新的视图控制器,导航栏显示在屏幕3,4和5中。

If you look at Screen 1, it doesn't have any nav bar at the top but when you touch any options it will push to a new view controller and have the nav bar appear as in Screen 3,4 and 5.

希望任何人都可以帮助我。谢谢你们!

Hope anyone could help me with this.Thanks a lot!

推荐答案

在我的大多数应用程序中,我都有一个自定义的UIViewController类,我从中派生出所有其他自定义控制器。在其中一些中,我向其他类可以覆盖的基类添加了一个类似 navigationBarInitiallyHidden 的方法。默认结果取决于应用程序的性质。

In most of my applications I have a custom UIViewController class that I derive all other custom controllers from. In some of these, I added a method like navigationBarInitiallyHidden to the base class that other classes can override. The default result depends on the nature of the application.

在导航控制器的委托中,当显示实现该方法的控制器时,委托隐藏或显示相应的导航控制器。由于我为hide或show设置了动画,因此我会检查当前状态,如果不需要更改则不执行任何操作。

In the delegate of the navigation controller, when a controller is being shown that implements that method, the delegate hides or shows the navigation controller accordingly. Since I animate the hide or show, I check the current state and do nothing if no change is needed.

您可以在委托方法中执行更简单的操作。如果显示的控制器是根控制器,则隐藏导航栏,否则显示它是否隐藏。

You could do something simpler in your delegate method. If the controller being shown is the root controller, hide the navigation bar, otherwise show it if it is hidden.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  if ( viewController == rootController ) {
    [navigationController setNavigationBarHidden:YES animated:animated];
  } else if ( [navigationController isNavigationBarHidden] ) {
    [navigationController setNavigationBarHidden:NO animated:animated];
  }
}

这篇关于如何隐藏/禁用第一个uinavigationbar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆