代码之家  ›  专栏  ›  技术社区  ›  LF-DevJourney

Uitableview下移

  •  0
  • LF-DevJourney  · 技术社区  · 8 年前

    我有两个并排的TableView,当我滚动两个表中的任何一个时,我使用下面的代码使它们像一个表一样滚动。

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView == self.coinNameTableView {
            self.coinInfoTableView?.setContentOffset(CGPoint.init(x: scrollView.contentOffset.x, y: scrollView.contentOffset.y), animated: false)
        }
        if scrollView == self.coinInfoTableView {
            self.coinNameTableView?.setContentOffset(CGPoint.init(x: scrollView.contentOffset.x, y: scrollView.contentOffset.y), animated: false)
        }
    }
    

    但有一个问题,当第一个单元格位于表的开头时,我向下滚动,整个表将向下移动,而不会反弹回原始位置。

    1 回复  |  直到 8 年前
        1
  •  1
  •   pkc456    8 年前

    在 scrollViewDidScroll 方法,写入逻辑 content offset 。如果内容偏移量小于0,则设置内容偏移量==0。

    参考代码:-

    if scrollView.ContentOffset.y < 0{
    self.coinInfoTableView?.setContentOffset(CGPoint.init(x: 0, y: 0), animated: false)
    
    self.coinNameTableView?.setContentOffset(CGPoint.init(x: 0, y: 0), animated: false)
    
    }