iPhone项目需要“提升以刷新”特征 [英] iPhone projects needs "Pull-up to refresh" feature

查看:100
本文介绍了iPhone项目需要“提升以刷新”特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多iPhone项目使用Pull-to-Refresh模式来加载更多结果(通常来自服务器的新数据。

Many iPhone projects use "Pull-to-Refresh" pattern to load more results (usually new data from the server.

在我的项目中,我想做的只是相反:上拉刷新。我想从服务器加载旧数据,但我需要用户请求数据拉起UITableView。

In my project I want to do just the opposite: "pull-up to refresh". I want to load old data from the server but I need that the user request the data pulling up the UITableView.

如何我能做到吗?有人可以帮助我吗?

How can I do it? Can anybody help me?

推荐答案

以下是我一直在使用的内容:

Here's what I've been using:

首先,你有一个持有拉起刷新消息的视图,并将其分配给:

First of all you have a view holding the "Pull up to refresh message", and assign it to:

[pullUpView setFrame:CGRectMake(0, [tableView rectForFooterInSection:0].origin.y, [tableView bounds].size.width,pullUpView.frame.height)];

然后设置两个委托方法,如下所示跟踪拖动。

Then you setup two delegate methods as below to track the dragging.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {    
    if (scrollView.isDragging) {
        CGFloat thresholdToRelease = [pullUpView frame].origin.y - [scrollView bounds].size.height;
        CGFloat thresholdToLoad = thresholdToRelease + [pullUpView frame].size.height;

        if (([scrollView contentOffset].y >= thresholdToRelease) && ([scrollView contentOffset].y < thresholdToLoad)) {
            [pullUpView reset];
        } else if ([scrollView contentOffset].y >= thresholdToLoad) {
            [pullUpView indicateThresholdRearched];
        }
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    CGFloat thresholdToAction = [pullUpView frame].origin.y + [pullUpView frame].size.height - [scrollView bounds].size.height;

    if ([scrollView contentOffset].y >= thresholdToAction) {
        if (!performingAction) {

            [pullUpView startLoading];

            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.5];
            [tableView setContentInset:UIEdgeInsetsMake(0, 0, [pullUpView frame].size.height, 0)];
            [UIView commitAnimations];

            /* do your things here */
            performingAction = YES;
        }
    }
}

最后还原tableView的contentInset隐藏pullUpView。

At the end revert the tableView's contentInset to hide the pullUpView.

这篇关于iPhone项目需要“提升以刷新”特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆