简体   繁体   English

在不显示标签栏的情况下对另一个导航控制器执行segue

[英]Perform segue to another Navigation Controller without showing Tab Bar

I have a root Tab Host Controller with two Navigation Controller tab siblings: (1) Nearby Stops and (2) Saved Stops. 我有一个带有两个“ Navigation Controller选项卡兄弟姐妹的根Tab Host Controller :(1)附近的站点和(2)已保存的站点。 Each of these has a View Controller respectively. 这些每个都有一个View Controller

I would like to perform a segue from one of the sibling View Controllers to another Navigation Controller with Stop Schedule View Controller embedded in it, with the following requirements: 我想从一个同级View Controllers到另一个嵌入了Stop Schedule View Controller的Navigation Controller执行segue,其具有以下要求:

  1. The root Tab Bar should not show at the bottom of this View Controller Tab Bar不应显示在此View Controller的底部
  2. I need to pass a Stop object to this View Controller before performing the segue 我需要在执行segue之前将Stop对象传递给此View Controller

Storyboard: 故事板: 在此处输入图片说明

Currently, I am performing a segue this way, though the Tab Bar remains on the Stop Schedule View Controller when it shouldn't. 目前,我正在以这种方式执行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)
}

You can simply set the hidden property of your tab bar when the stop schedule view controller is displayed and unhide the tab bar before that view controller disappears 您可以在显示停止时间表视图控制器时简单地设置标签栏的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
}

Update: To animate the transition you can use this: 更新:要制作过渡动画,您可以使用以下方法:

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

        }
    }
}

在此处输入图片说明

You are not using the segue you just defined in your Storyboard. 您没有使用您在情节提要中定义的segue。 Instead, you are currently reloading your StopScheduleViewController manually, whereas you should only perform the segue you already have defined. 相反,您当前正在手动重新加载StopScheduleViewController ,而您应该仅执行已经定义的segue

Add an Identifier to each of the Storyboard Segue you want to invoke programmatically, 向要以编程方式调用的每个Storyboard Segue添加一个标识符

序列标识符

then load them in this manner: 然后以这种方式加载它们:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("showStopSchedule", sender: self)
}

使用情节提要Segue动画

如果您只想隐藏navigationController,则以下代码适用。

  self.navigationController?.navigationBar.hidden = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM