iPhone - how to scroll two UITableViews symmetrically

前端 未结 5 1375
天命终不由人
天命终不由人 2021-01-01 05:27

In my app, I have two tableViews side by side. When the user scrolls on, I would like the second one to scroll at the same time, so it looks almost like one table with two d

5条回答
  •  礼貌的吻别
    2021-01-01 05:58

    UITableView is a subclass of UIScrollView. Swift solution:

    extension yourViewController: UIScrollViewDelegate {
        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            let otherScrollView = (scrollView == tableViewLeft) ? tableViewRight : tableViewLeft
            otherScrollView?.setContentOffset(scrollView.contentOffset, animated: false)
        }
    }
    

    And stop the bounce of both the tables

    tableViewLeft.bounces = false
    tableViewRight.bounces = false
    

    If you want to make vertical scroll Indicators go, write the below code

    tableViewLeft.showsVerticalScrollIndicator = false
    tableViewRight.showsVerticalScrollIndicator = false
    

提交回复
热议问题