欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[ios] 首页隐藏navigation bar

程序员文章站 2022-03-26 19:19:52
...

How to hide a navigation bar from first ViewController in Swift?

refer to : 

http://*.com/questions/29209453/how-to-hide-a-navigation-bar-from-first-viewcontroller-in-swift

 

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAappear(animated)
    // Hide the navigation bar on the this view controller
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    // Show the navigation bar on other view controllers
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

 

原理:因为setNavigationBarHidden设置是全局的,所有页面都会响应。所以通过页面出现时消失,到其他页时显示来实现。

 

object-c method:

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

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