objective-c 当我从导航控制器推送时如何隐藏导航栏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1617565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:23:52  来源:igfitidea点击:

how to hide navigationbar when i push from navigation controller?

iphoneobjective-cuinavigationcontrolleruinavigationbar

提问by senthilMuthu

how to hide top bar in UIViewcontrollerwhen i push from navigation controller using pushViewController? any help please?

当我使用pushViewController从导航控制器推送时 如何隐藏UIViewcontroller 中的顶部栏?有什么帮助吗?

回答by Ed Marty

Put this code in the view controller you want to hide the navigation bar for.

将此代码放在要为其隐藏导航栏的视图控制器中。

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

And you may also want to stick this in there, depending on your needs:

你可能还想把它放在那里,这取决于你的需要:

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

回答by dustinrwh

Here's how to do it in Swift 3:

以下是如何在Swift 3 中执行此操作:

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

P.S. I found that if you set animated to false, a black bar appears on push. But when it is set to trueit's smooth as silk!

PS我发现如果您将动画设置为false,则推送时会出现黑条。但是当它被设置时它true像丝绸一样光滑!

回答by Zahur

For iOS 8 May be this work around could work it

对于 iOS 8 可能是这个工作可以解决

CATransition* transition = [CATransition animation];
        transition.duration = 0.3;
        transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromRight;
        [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
        [self.navigationController setNavigationBarHidden:TRUE animated:FALSE];
        [self.navigationController pushViewController:productViewObj animated:FALSE];
        [productViewObj.navigationController setNavigationBarHidden:TRUE animated:FALSE];
        [productViewObj release];