我从导航控制器推出时如何隐藏导航栏?

时间:2009-10-24 10:08:55

标签: iphone objective-c uinavigationcontroller uinavigationbar

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

3 个答案:

答案 0 :(得分:103)

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

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

您可能还想根据自己的需要坚持下去:

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

答案 1 :(得分:7)

以下是 Swift 3

中的操作方法
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

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

答案 2 :(得分:0)

适用于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];