将导航栏设置为隐藏,具体取决于视图控制器的显示方式 [英] Set navigation bar hidden, depending on how the view controller appeared

查看:138
本文介绍了将导航栏设置为隐藏,具体取决于视图控制器的显示方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中一个标签中有一个带有导航控制器的标签栏。目前导航控制器的根视图没有导航栏显示和动画很好地进入子视图

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.

有一种方法,我

推荐答案

可以在根视图上隐藏导航栏而不对其进行动画处理(BOOL)动画参数 viewWillAppear:animated 。当更改Tabs时,它将作为 NO ,因为动画是立即的。另一方面,如果正在或从导航堆栈或 animated: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.

虽然这看起来像一个黑客,这是正确的方式:你不需要找出谁是呼叫者,而不是,关注的事实,如果您的视图控制器将出现动画,你有时间做自己的动画,如果没有,拧,它显示(或在这种情况下,隐藏)一切立即。

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.

这篇关于将导航栏设置为隐藏,具体取决于视图控制器的显示方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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