iPhone仅在第一页上隐藏导航栏 [英] iPhone hide Navigation Bar only on first page

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

问题描述

我有下面的代码隐藏并显示导航栏。当第一个视图加载时隐藏它,然后在调用children时隐藏它。麻烦的是,当他们回到根视图时,我找不到触发它再次隐藏的事件/动作....

I have the code below that hides and shows the navigational bar. It is hidden when the first view loads and then hidden when the "children" get called. Trouble is that I cannot find the event/action to trigger it to hide again when they get back to the root view....

我有一个测试按钮在手动执行操作的根页面上,但它并不漂亮,我希望它是自动的。

I have a "test" button on the root page that manually does the action but it is not pretty and I want it to be automatic.

-(void)hideBar 
{
    self.navController.navigationBarHidden = YES;
}
-(void)showBar 
{       
    self.navController.navigationBarHidden = NO;
}


推荐答案

我找到的最好的解决方案是在第一个视图控制器中执行以下操作。

The nicest solution I have found is to do the following in the first view controller.

Objective-C

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

Swift

override func viewWillAppear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
    super.viewWillAppear(animated)
}

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: animated)
    super.viewWillDisappear(animated)
} 

这将导致导航栏从左侧动画(与下一个视图)当您按下堆栈上的下一个 UIViewController 时,当您按下<上的后退按钮时,向左移动(与旧视图一起) code> UINavigationBar 。

This will cause the navigation bar to animate in from the left (together with the next view) when you push the next UIViewController on the stack, and animate away to the left (together with the old view), when you press the back button on the UINavigationBar.

请注意,这些不是委托方法,你要重写 UIViewController 这些方法的实现,并根据您必须的文档所有超级实施在您的实施中的某个地方

Please note also that these are not delegate methods, you are overriding UIViewController's implementation of these methods, and according to the documentation you must call the super's implementation somewhere in your implementation.

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

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