隐藏导航栏? [英] Hide navigationBar?

查看:30
本文介绍了隐藏导航栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1) 下面三行代码有什么区别?

2) 另外,如果我返回到 viewController 并且前一个 viewController 通过相同的方法将导航栏设置为隐藏,为什么只有第三行代码有效 [self.navigationController setNavigationBarHidden:NO] 我的假设是所有三行都做同样的事情?

2) Also why does only the third line of code work if I'm returning to a viewController and the previous viewController has set the navigationBar to hidden through the same approach [self.navigationController setNavigationBarHidden:NO] my assumption was that all three lines do the same thing?

self.navigationController.navigationBar.hidden = NO;
[self.navigationController.navigationBar setHidden:NO];
[self.navigationController setNavigationBarHidden:NO];

跟进:

为什么当我需要运行此代码时:

Why when I need to run this code:

[self.navigationController.navigationBar setBackgroundImage:incorrectAnswerNavigationBarBackgroundImage forBarMetrics:UIBarMetricsDefault]; 

它只能工作,正在设置背景图像,否则导航栏只是白色.

It only works, working being setting the background image, otherwise the nav bar is just white.

如果我有这两行:

[self.navigationController setNavigationBarHidden:NO]; 
self.navigationController.navigationBar.hidden = NO;

如果我省略 self.navigationController.navigationBar.hidden = NO; 导航栏的空间会弹出,但它只是白色,没有背景图像.如果我有两条线,它就可以工作并且有背景图像.

If I leave out self.navigationController.navigationBar.hidden = NO; the space for the nav bar pops down but it's just white, there is no background image. If I have both lines it works and there is a background image.

推荐答案

前两个在功能上是相同的;不同之处在于一个使用点表示法,而另一个不使用.这两个方法都在导航控制器的 navigationBar 属性上触发 - (void) setHidden:(BOOL)hide.

The first two are functionally identical; the difference being one uses the dot notation while the other doesn't. These two methods both fire - (void) setHidden:(BOOL)hide on the navigationBar property on the navigation controller.

现在第三个是完全不同的方法.它是 - (void) setNavigationBarHidden:(BOOL)hide 并在 UINavigationController 上定义.这个方法起作用的原因是这个方法通知导航控制器您希望隐藏导航栏,而前两个手动将导航栏设置为隐藏.如果 UINavigationController 调用任何修改导航栏隐藏属性的方法,则前两个更改将被撤消,因此创建了 setNavigationBarHidden: 方法以便您有办法通知 UINavigationController 无论它做什么,它都应该隐藏导航栏,而不是将其更改为显示.

Now the third one is a completely different method. It's - (void) setNavigationBarHidden:(BOOL)hide and is defined on UINavigationController. The reason why this one works is this method is informing the navigation controller that you wish the navigation bar to be hidden while the first two manually set the navigation bar to be hidden. The first two's changes are undone if UINavigationController calls any methods that modify the hidden property of the navigation bar, hence why the setNavigationBarHidden: method was created so you'd have a way of informing UINavigationController that no matter what it does, it should hide the navigation bar and not change it to be showing.

对于这个问题的第二部分,您实际上需要在 UINavigationController 上调用 - (void)setNavigationBarHidden:(BOOL)hidden animation:(BOOL)animated>.这是 UINavigationController 的正确记录方法.

For the second part of this question, you actually need to be calling - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated on UINavigationController. That's the proper documented method for UINavigationController.

这篇关于隐藏导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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