如何配置uiscrollview来加载数据,当它达到底点时

时间:2013-04-09 09:25:26

标签: ios uiscrollview triggers

我正在制作一个应用程序,就像InstagramPath等。我需要知道,触发点,如果用户滚动到底部点并且当它反弹时,我需要拨打电话。我如何获得该触发点?

2 个答案:

答案 0 :(得分:2)

查看UIScrollviewDelegate方法:http://developer.apple.com/library/ios/#documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html

您可能希望查看– scrollViewDidEndDragging:willDecelerate:– scrollViewDidEndDecelerating:,然后在这些方法中使用scrollView.bounds检查滚动视图的当前可见矩形,以确定用户是否已滚动到底部

答案 1 :(得分:0)

您可以查看以下代码。它可能对你有帮助。

- (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];
}