Reputation: 481
Please see the storyboard below:
I need to dynamically hide UINavigationBar for UITableViewController "Zero" and show it for UITableViewController "One" and "Two".
What is the best approach?
Upvotes: 0
Views: 1540
Reputation: 127
I implemented a method which hides the NavigationController very smooth after one second... I prefer this than just hiding it ;)
var navigation: UINavigationController!
override func viewDidLoad() {
navigation = navigationController!
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "animate", userInfo: nil, repeats: false)
}
func animate(){
hideController(self.navigation)
}
func hideController(navigationController: UINavigationController){
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
self.navigationController.alpha = 0.0
}, completion: nil)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
if self.navigationController!.respondsToSelector("interactivePopGestureRecognizer") {
timer.invalidate()
UIApplication.sharedApplication().statusBarHidden = false
}
}
I hope I could help you
you could also put the hide function into another class, so you don't need to retype it in the other views.
Edit:
I forgot to mention.. When you go one view back, you need to set you NavigationController back to visible... Therefore create another method for example the function show
and set it's alpha to 1.0
func show(navigationController: UINavigationController){
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
self.navigationController.alpha = 1.0
}, completion: nil)
}
Upvotes: 0
Reputation: 1174
try this..
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true
}
you could use viewWillDisappear to set it to visible again
Upvotes: 1
Reputation: 5248
You can set the hidden
property of the UINavigationBar
when the views appear...
self.navigationController?.navigationBar.hidden = true
Just do this in the views where you want the nav bar hidden
Upvotes: 0