Set navigation bar hidden, depending on how the view controller appeared(隐藏导航栏,取决于视图控制器的显示方式)
问题描述
我在其中一个选项卡中有一个带有导航控制器的选项卡栏.目前,导航控制器的根视图没有显示导航栏,并且通过
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.
这篇关于隐藏导航栏,取决于视图控制器的显示方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:隐藏导航栏,取决于视图控制器的显示方式
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
