How to configure uiscrollview to load data, when it reaches the bottom point [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-23 06:02:51

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/15898215/how-to-configure-uiscrollview-to-load-data-when-it-reaches-the-bottom-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!