Limit the scroll for UITableView

后端 未结 5 882
不知归路
不知归路 2021-01-13 14:27

I have a TableViewController:

\"enter

As you see I have my own custom bar at t

5条回答
  •  醉酒成梦
    2021-01-13 15:00

    I had the same problem and asked our UX-Designer, how it would be better to do. He said, that both strict solutions (prevent bouncing or allow it as it is) are bad. It's better to allow bouncing but only for some space

    My solution was:

    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView == self.tableView {
            if scrollView.contentOffset.y < -64 {
                scrollView.scrollRectToVisible(CGRect(origin: CGPoint(x: 0, y: -64), size: scrollView.frame.size), animated: false)
                scrollView.scrollRectToVisible(CGRect(origin: CGPoint.zero, size: scrollView.frame.size), animated: true)
            }
        }
    }
    

    Where 64 was that "some space" for me. Code stops tableView at -64 from the top and brings it up with an animation. Good luck!

提交回复
热议问题