3

I have the following code in place to grab the event when a UIScrollView reaches then end of its content view:

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    // CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
    // [scrollView setContentOffset:bottomOffset animated:NO];

    if (currentEndPoint >= scrollView.contentSize.height)
    {
        // We are at the bottom

I notice that when I scroll to the bottom it hits it and bounces back up.

If I add this:

CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:NO];

then the scroll goes back to the bottom.

Is there any way for it to stay at the bottom without the "bounce back up" as in once it hits the bottom, stop it from moving.

Thanks.

cdub
  • 24,555
  • 57
  • 174
  • 303
  • 1
    May be you need use `- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset` instead `scrollViewDidEndDecelerating:`? – Cy-4AH May 15 '15 at 06:09

3 Answers3

7

You should uncheck the bounce property of scrollview. Check the screenshot!

enter image description here

Ritu
  • 661
  • 3
  • 8
  • scrollView.bounces = NO; is what I wanted. Didn't see that at first in the property list – cdub May 15 '15 at 06:06
  • @Ritu Can you please tell me how to take screen shot of IB. – Ashok Londhe May 15 '15 at 09:49
  • @AshokLondhe On mac, to take a screenshot, hold Shift+Option+4. It will show a focus pointer. Now drag mouse to select the area to take screenshot – Ritu May 15 '15 at 09:53
2

I didn't understand much what you mean, what I got that you want to stop scrolling of table view when it reaches to bottom. So here is the process:-

- (void) scrollViewDidEndDecelerating:(UIScrollView *) scrollView
{
    float currentEndPoint = scrollView.contentOffset.y + scrollView.frame.size.height;

    if (currentEndPoint >= scrollView.contentSize.height)
    {

    CGPoint offset = scrollView.contentOffset;
    offset.x -= 1.0;
    offset.y -= 1.0;
    [scrollView setContentOffset:offset animated:NO];
    offset.x += 1.0;
    offset.y += 1.0;
    [scrollView setContentOffset:offset animated:NO];
  }
}
Vizllx
  • 9,135
  • 1
  • 41
  • 79
0

bounce back problem, u can resolve by

  var progressScrollView = UIScrollView()
  progressScrollView.bounces = false
Energy
  • 940
  • 13
  • 20