[ios] 首页隐藏navigation bar

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

refer to : 

http://stackoverflow.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;
}

 

猜你喜欢

转载自jameskaron.iteye.com/blog/2344469
bar