如何在iPhone中隐藏导航栏? [英] How to hide navigation bar in iPhone?

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

问题描述

目前我在iPhone应用程序中工作,我有两个屏幕,如A和B,A没有导航栏,但B有导航栏。所以我这样设置。

Currently i am working in iPhone app, I have two screen like A and B, A has no navigation bar, but B has navigation bar. so i set like this.

A类:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"A";
    [self.navigationController setNavigationBarHidden:YES];
}

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

B类:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"B";
    [self.navigationController setNavigationBarHidden:NO];
}

-(void)Previousscreen
{
  [self.navigationController popViewControllerAnimated:YES];
}

然后我运行应用程序,当我去上一堂课如B到A当时蓝色显示在B级以下附加屏幕截图供您参考。如何解决这个问题?请帮助我

then i run the application, When i go to previous class like B to A at the time blue color show in B class below attached screen shot for your reference. How to fix this issue? please help me

提前致谢

推荐答案

您需要使用以下代码:

You'll need to use this code:

[navigationController setNavigationBarHidden:YES animated:YES]

在两个类的视图生命周期中的 - (void)viewWillAppear:(BOOL)动画 或更高版本。 [避免在 - (void)viewDidLoad 中执行此操作。]

in - (void)viewWillAppear:(BOOL)animated or later in the view lifecycle in both classes. [Avoid doing this in - (void)viewDidLoad.]

这里的诀窍是使用 setNavigationBarHidden:动画方法(代替更简单的 setNavigationBarHidden:方法)。这将确保您的UI问题消失以及由此产生的任何位置问题。

The trick here is in using the setNavigationBarHidden:animated: method (in place of the simpler setNavigationBarHidden: method). This will ensure your UI issue goes away and also any positional issues due to it.

P.S。如果你检查 self.navigationController。 navigationBarHidden (而不是 self.navigationController。 navigationBar.hidden )的值需要检查导航栏是否在某些时候隐藏在代码中。

P.S. Check the value of self.navigationController.navigationBarHidden (instead of self.navigationController.navigationBar.hidden) if you need to check if your navigation bar is hidden, at some point, in your code.

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

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