How can I refresh the table view but disable the bounce?
Asked Answered
U

2

5

I want to disable my scrollview bounce when scroll down.

enter image description here

When I disable bounce vertically I can't refresh my table. Any suggestion how to disable bounce, but enable refresh table?

I'm refreshing this way:

self.refreshControl = UIRefreshControl()
    self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refreshControl)

func refresh(sender:AnyObject) {
    getJson()
    self.tableView.reloadData()
    self.refreshControl.endRefreshing()
}

Thanks.

Unblessed answered 23/12, 2015 at 11:36 Comment(3)
"disable bounce"? What do you mean?Pereira
I think there are no way to do it.Phonogram
how are you trying to refresh your table view?Paske
U
9

Just did it this way:

func scrollViewDidScroll(scrollView: UIScrollView) {

    if scrollView.contentOffset.y < 0.0 {
        return
    }

    if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
        scrollView.setContentOffset(CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
    }
}
Unblessed answered 23/12, 2015 at 11:50 Comment(0)
E
0

Implement the scrollViewDidScroll method in the UIScrollViewDelegate

  extension ViewController: UIScrollViewDelegate {
      func scrollViewDidScroll(_ scrollView: UIScrollView) {
          if scrollView.contentOffset.y > 0 {
              scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x, y: 0), animated: false)
          }
      }
    }

This allows the table view to pull to refresh down, but restricts pulling up. This removes the bounce in the upwards direction.

Side-effect: this will not let you go beyond the cells already on view, so you can't scroll down to cells not visible.

Ecbatana answered 28/1, 2020 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.