Disable UIScrollView bounce at the top of the screen

I have a UIScrollView in my application with vertical rollback enabled. I need a rebound at the bottom of the screen, but not turned on at the top of the screen.

No, how to detect scrollview with the following:

  (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

  // no bounce if scrollView has reached the top of the screen ??
  }
+4
source share
2 answers

Try setting the property bouncesas scroll scrolling based on the content offset:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    scrollView.bounces = (scrollView.contentOffset.y > 100);
}
+20
source

SWIFT

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    //disable bounce only at the top of the screen
    scrollView.bounces = scrollView.contentOffset.y > 100
}
+1
source

Source: https://habr.com/ru/post/1534070/


All Articles