如何从一个特定的视图控制器隐藏导航栏

时间:2012-02-11 09:14:53

标签: ios cocoa-touch

我创建了一个两个闪屏的iPhone应用程序。之后用户被带到第一个视图。我添加了一个UINavigationController。它工作得很好。

如何单独删除打开视图的导航栏?

主窗口

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


self.splashScreen = [[SplashScreen alloc] 
                initWithNibName:@"SplashScreen" 
                bundle:nil];
if (self.pageController == nil) {
openingpage *page=[[openingpage alloc]initWithNibName:@"openingpage" bundle:[NSBundle mainBundle]];
    self.pageController = page;
    [page release];
}
[self.navigationController pushViewController:self.pageController animated:YES];

[window addSubview:splashScreen.view];

 [splashScreen displayScreen];
[self.window makeKeyAndVisible];

return YES;
 }

7 个答案:

答案 0 :(得分:144)

因此,如果您在某些视图中,控制器必须使用此方法:

[self.navigationController setNavigationBarHidden:YES animated:YES];

更多说明:

UINavigationController有一个属性navigationBarHidden,它允许你隐藏/显示整个导航控制器的导航栏。

让我们在下一个等级中掠夺:

--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3

三个UIViewController中的每一个都有导航栏,因为它们位于UINavigationController中。例如,你想将bar隐藏到第二个(实际上它与哪一个无关),然后写入UIViewController2:

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

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

答案 1 :(得分:16)

斯威夫特4:

terraform env

答案 2 :(得分:3)

这对我有用:

雨燕4

INDEX(data_id, customer_id)

答案 3 :(得分:1)

最好记住它是否以前被隐藏了:

private var navigationBarWasHidden = false

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Save if it was hidden initially
    self.navigationBarWasHidden = self.navigationController?.isNavigationBarHidden ?? false
    // Hide the Navigation Bar
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    // Show the Navigation Bar
    self.navigationController?.setNavigationBarHidden(self.navigationBarWasHidden, animated: animated)
}

答案 4 :(得分:0)

使用下面一行代码隐藏Swift3和Swift4中的导航栏

            CheckBox active = (CheckBox)editableItem["valid"].Controls[0];
        Boolean bactive = active.Checked;

显示导航栏

navigationController?.setNavigationBarHidden(true, animated: true)

答案 5 :(得分:0)

在c#或Xamarin.IOS中, this.NavigationController.NavigationBar.Hidden = true;

答案 6 :(得分:-2)

以模态方式显示开场视图,或;

  1. 不要将其添加到导航控制器
  2. 在导航控制器之前显示
  3. 一旦加载了所有内容,请关闭开始视图并显示导航控制器(两者都没有动画)。

  4. 以此话题为例:How can I display a splash screen for longer on an iPhone?

    -(void)applicationDidFinishLaunching:(UIApplication *)application {
        [window addSubview:splashView];
        [NSThread detachNewThreadSelector:@selector(getInitialData:) 
                                     toTarget:self withObject:nil];
    }
    
    -(void)getInitialData:(id)obj {
        [NSThread sleepForTimeInterval:3.0]; // simulate waiting for server response
        [splashView removeFromSuperview];
        [window addSubview:tabBarController.view];
    }