我在其中一个选项卡中有一个带有导航控制器的选项卡栏.目前,导航控制器的根视图没有显示导航栏,并且通过
I have a tab bar with a navigation controller in one of the tabs. Currently the root view of the navigation controller doesnt have the nav bar showing and animates nicely into the subviews by
- (void)viewDidLoad {
...
[self.navigationController setNavigationBarHidden:YES animated:NO];
...
}
和
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
当然,更改选项卡会启动 viewWillAppear
功能,因此当我返回根视图时,导航栏会滑开,而不是不存在.
But of course changing tabs initiates the viewWillAppear
function and so as I go back to the root view the navigation bar slides away, rather than just not being there.
有没有一种方法可以隐藏根视图上的导航栏而不对其进行动画处理,除非从导航堆栈上的子视图中出现?
Is there a way that I can hide the nav bar on the root view without animating it except for when appearing from a subview on the navigation stack?
viewWillAppear:animated
上的 (BOOL)animated
参数.更改选项卡时,它会以 NO
的形式出现,因为动画是即时的.另一方面,如果使用 animated:YES
从导航堆栈中推送或弹出,那么它将作为YES
.
The (BOOL)animated
parameter on viewWillAppear:animated
. When changing Tabs, it will come as NO
, since the animation is immediate. On the other hand, if it's being pushed or popped from the navigation stack with animated:YES
, then it will come as YES
.
虽然这看起来像个 hack,但它是正确的方法:你不需要弄清楚谁是调用者,相反,专注于这样一个事实:如果你的视图控制器会显示动画,你有时间做你自己的动画,如果没有,就把它搞砸,立即显示(或在这种情况下,隐藏)所有内容.
Although this looks like a hack, it's the correct way: you don't need to figure out who was the caller, instead, focus on the fact that if your view controller will appear animated, you have time to do your own animations, if not, screw it, show (or in this case, hide) everything immediately.
这篇关于隐藏导航栏,取决于视图控制器的显示方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!