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;
}
本文介绍了一种在Swift中仅针对首个ViewController隐藏导航栏的方法。通过覆盖viewWillAppear和viewWillDisappear方法,可以实现在进入第一个页面时隐藏导航栏,并在切换到其他页面时重新显示导航栏的功能。这种方法适用于需要个性化导航体验的应用。
611

被折叠的 条评论
为什么被折叠?



