执行segue到另一个导航控制器而不显示标签栏

时间:2016-01-27 22:11:39

标签: ios swift uinavigationcontroller uitabbarcontroller xcode7

我有一个根Tab Host Controller,其中包含两个Navigation Controller标签页:(1)附近停靠点和(2)已保存停靠点。其中每个都分别有View Controller

我想从其中一个兄弟View Controllers到另一个Navigation Controller执行一个segue,其中嵌入了停止计划视图控制器,具有以下要求:

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

    故事板: enter image description here

    目前,我正在以这种方式执行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)
    }
    

3 个答案:

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

        }
    }
}

enter image description here

答案 1 :(得分:1)

您没有使用故事板中定义的segue。相反,您目前正在手动重新加载StopScheduleViewController,而您只应执行已定义的segue

为要以编程方式调用的每个 Storyboard Segue 添加标识符

segue identifier

然后以这种方式加载它们:

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

Use Storyboard segue animation

答案 2 :(得分:1)

如果您只想隐藏navigationController,则以下代码可以正常工作。

  self.navigationController?.navigationBar.hidden = true