gpt4 book ai didi

ios - 在不显示选项卡栏的情况下执行到另一个导航 Controller 的转场

转载 作者:搜寻专家 更新时间:2023-11-01 05:57:40 25 4
gpt4 key购买 nike

我有一个根 Tab Host Controller 和两个 Navigation Controller 选项卡兄弟:(1) Nearby Stops 和 (2) Saved Stops。其中每一个都有一个 View Controller

我想执行一个从兄弟 View Controllers 到另一个嵌入了 Stop Schedule View Controller 的 Navigation Controller 的 segue,具有以下要求:

  1. Tab Bar 不应显示在此 View Controller 的底部
  2. 在执行 segue 之前,我需要将一个 Stop 对象传递给这个 View Controller

Storyboard: enter image description here

目前,我正在以这种方式执行 segue,尽管 Tab Bar 在不应该保留在 Stop Schedule View Controller 上。

func showStopSchedule(stop: Stop) {
let stopScheduleController = self.storyboard?.instantiateViewControllerWithIdentifier("StopScheduleViewController") as! StopScheduleViewController

stopScheduleController.stop = stop // pass data object

self.navigationController?.pushViewController(stopScheduleController, animated: true)
}

最佳答案

您可以在显示停止计划 View Controller 时简单地设置选项卡栏的隐藏属性,并在该 View Controller 消失之前取消隐藏选项卡栏

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
})

}
}
}

enter image description here

关于ios - 在不显示选项卡栏的情况下执行到另一个导航 Controller 的转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35049074/

25 4 0