0

I am making an application, just like Instagram, Path, etc. I need to know, trigger point, where, if the user scrolls to the bottom point and when it bounces, I need to make some calls. How do I get that trigger point?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sumitiscreative
  • 647
  • 3
  • 10
  • 24

2 Answers2

2

Take a look at the UIScrollviewDelegate methods: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html

You probably want to look at – scrollViewDidEndDragging:willDecelerate: and – scrollViewDidEndDecelerating: and then inside those methods check the current visible rect of the scrollview using scrollView.bounds to find out if the user has scrolled to the bottom.

JDx
  • 2,615
  • 3
  • 22
  • 33
  • okay, checking bounds of scrollview is the key, but i have read somewhere you need to take care of insets also, how to do that. Bcz data will be loaded once user makes scroll view bounce at the bottom ... – Sumitiscreative Apr 09 '13 at 11:58
0

You can check the below code. It may help you.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    scrollView.contentInset = UIEdgeInsetsMake(0.0, 0.0, 60.0, 0.0);

    [scrollView scrollRectToVisible:CGRectMake(0, scrollView.contentSize.height, scrollView.frame.size.width, 160.0) animated:YES];

    if ([scrollView viewWithTag:5000])
    {
        UIView *view = (UIView*)[scrollView viewWithTag:5000];
        [view removeFromSuperview], view = nil;
    }

    UIView *viewloader = [[[UIView alloc] initWithFrame:CGRectMake(0.0, scrollView.contentSize.height, scrollView.contentSize.width, 160.0)] autorelease];
    viewloader.tag = 5000;

    UILabel *lblloader = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, scrollView.frame.size.width-0.0, 60.0)] autorelease];
    lblloader.backgroundColor = [UIColor clearColor];
    lblloader.tag = 550;
    lblloader.textColor = [UIColor whiteColor];
    lblloader.textAlignment = NSTextAlignmentCenter;
    lblloader.text = @"Click to load more data.";
    [viewloader addSubview:lblloader];
    viewloader.backgroundColor = [UIColor darkGrayColor];

    UIButton *btnLoad = [UIButton buttonWithType:UIButtonTypeCustom];
    btnLoad.frame = lblloader.frame;
    btnLoad.backgroundColor = [UIColor clearColor];
    [btnLoad addTarget:self action:@selector(callForMoreData:) forControlEvents:UIControlEventTouchUpInside];
    [viewloader addSubview:btnLoad];

    [scrollView addSubview:viewloader];
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Exploring
  • 925
  • 6
  • 18