简体   繁体   中英

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. Each of these has a View Controller respectively.

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:

  1. The root Tab Bar should not show at the bottom of this View Controller
  2. I need to pass a Stop object to this View Controller before performing the segue

Storyboard: 在此处输入图片说明

Currently, I am performing a segue this way, though the Tab Bar remains on the Stop Schedule View Controller when it shouldn't.

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

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. Instead, you are currently reloading your StopScheduleViewController manually, whereas you should only perform the segue you already have defined.

Add an Identifier to each of the Storyboard Segue you want to invoke programmatically,

序列标识符

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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