如何隐藏和显示标签栏以及增加和减少tableView高度?

时间:2017-01-20 10:26:58

标签: ios swift uitableview uiscrollview uitabbarcontroller

我有一个UITabBarController,我添加了一个视图控制器。在我的UIViewController中,我有一个UITableView。

我的要求是每当我向下滚动tableView然后Tab键应该被隐藏,TableView应该全屏显示,当我向上滚动tableView时,TabBar不应该被隐藏。

这是我的故事板屏幕截图:

enter image description here

enter image description here

在图像中,您可以看到我已经使用了tableView和tabBar。而且当TabBar被隐藏时,我必须显示TableView高度。

这是我的代码:

//Change Tab bar
func changeTabBar(hidden:Bool, animated: Bool){
    let tabBar = self.tabBarController?.tabBar
    if tabBar!.isHidden == hidden{ return }
    let frame = tabBar?.frame
    let offset = (hidden ? (frame?.size.height)! : -(frame?.size.height)!)
    let duration:TimeInterval = (animated ? 0.5 : 0.0)
    tabBar?.isHidden = false
    if frame != nil
    {
        UIView.animate(withDuration: duration,
                       animations: {
                        tabBar!.frame = frame!.offsetBy(dx: 0, dy: offset)
                        //tabBar?.isHidden = true
                        //self.tableView.frame.size.height = self.tableView.frame.size.height + (tabBar?.frame.size.height)!
        },
                       completion: {

                        if $0 {tabBar?.isHidden = hidden}
        })
    }
}  

//ScrollView Delegate
extension reNewView : UIScrollViewDelegate {

  //Tab bar
  func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
      if scrollView.panGestureRecognizer.translation(in: scrollView).y < 0{

          changeTabBar(hidden: true, animated: true)
      }
      else{

          changeTabBar(hidden: false, animated: true)
      }
   }
 }  

怎么办?

我也检查了this link,但仍未得到正确答案。

0 个答案:

没有答案
相关问题