Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable UIScrollView bounce at the top of the screen

Tags:

ios

iphone

ipad

I have UIScrollView in my app with vertical bounce enabled. I need the bounce at the bottom of the screen but not enabled at the top of the screen.

I no how to detect scrollview with the following:

  (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

  // no bounce if scrollView has reached the top of the screen ??
  }
like image 943
pete Avatar asked Mar 29 '14 20:03

pete


2 Answers

Try setting the bounces property as the scroll view scrolls, based on the content offset:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    scrollView.bounces = (scrollView.contentOffset.y > 100);
}
like image 166
Wain Avatar answered Oct 19 '22 12:10

Wain


SWIFT

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    //disable bounce only at the top of the screen
    scrollView.bounces = scrollView.contentOffset.y > 100
}
like image 40
David Rees Avatar answered Oct 19 '22 11:10

David Rees