我实现了一个方法,它在一秒钟后非常平滑地隐藏 NavigationController...我更喜欢这个而不是仅仅隐藏它;)
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
}
}
希望能帮到你
您也可以将隐藏功能放入另一个类中,因此您无需在其他视图中重新键入它。
编辑:
我忘了提及.. 当您返回一个视图时,您需要将 NavigationController 设置回可见...因此创建另一个方法,例如函数 show 并将其 alpha 设置为 1.0
func show(navigationController: UINavigationController){
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
self.navigationController.alpha = 1.0
}, completion: nil)
}