我有一个根Tab Host Controller
,其中包含两个Navigation Controller
标签页:(1)附近停靠点和(2)已保存停靠点。其中每个都分别有View Controller
。
我想从其中一个兄弟View Controllers
到另一个Navigation Controller
执行一个segue,其中嵌入了停止计划视图控制器,具有以下要求:
Tab Bar
不应显示在此View Controller
Stop
对象传递给此View Controller
醇>
目前,我正在以这种方式执行segue,尽管Tab Bar
仍然在停止计划视图控制器上,但它不应该。
func showStopSchedule(stop: Stop) {
let stopScheduleController = self.storyboard?.instantiateViewControllerWithIdentifier("StopScheduleViewController") as! StopScheduleViewController
stopScheduleController.stop = stop // pass data object
self.navigationController?.pushViewController(stopScheduleController, animated: true)
}
答案 0 :(得分:4)
您可以在显示停止计划视图控制器时简单地设置标签栏的hidden
属性,并在该视图控制器消失之前取消隐藏标签栏
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.hidden=true
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.tabBar.hidden=false
}
更新:要为转换设置动画,您可以使用此功能:
class StopViewController: UIViewController {
var barFrame:CGRect?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// self.tabBarController?.tabBar.hidden=true
if let tabBar=self.tabBarController?.tabBar {
self.barFrame=tabBar.frame
UIView.animateWithDuration(0.3, animations: { () -> Void in
let newBarFrame=CGRectMake(self.barFrame!.origin.x, self.view.frame.size.height, self.barFrame!.size.width, self.barFrame!.size.height)
tabBar.frame=newBarFrame
}, completion: { (Bool) -> Void in
tabBar.hidden=true
})
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.tabBar.hidden=false;
if self.barFrame != nil {
UIView.animateWithDuration(0.3, animations: { () -> Void in
let newBarFrame=CGRectMake(self.barFrame!.origin.x, self.view.frame.size.height-self.barFrame!.size.height, self.view.frame.size.width, self.barFrame!.size.height)
self.tabBarController?.tabBar.frame=newBarFrame
})
}
}
}
答案 1 :(得分:1)
您没有使用故事板中定义的segue。相反,您目前正在手动重新加载StopScheduleViewController
,而您只应执行已定义的segue
。
为要以编程方式调用的每个 Storyboard Segue 添加标识符,
然后以这种方式加载它们:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("showStopSchedule", sender: self)
}
答案 2 :(得分:1)
如果您只想隐藏navigationController,则以下代码可以正常工作。
self.navigationController?.navigationBar.hidden = true