gpt4 book ai didi

iPhone项目需要 "Pull-up to refresh"功能

转载 作者:行者123 更新时间:2023-12-03 18:54:35 24 4
gpt4 key购买 nike

许多 iPhone 项目使用“拉动刷新”模式来加载更多结果(通常是来自服务器的新数据。

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

我该怎么做?有人可以帮助我吗?

最佳答案

这是我一直在使用的:

首先,您有一个包含“上拉刷新消息”的 View ,并将其分配给:

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

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

- (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。

关于iPhone项目需要 "Pull-up to refresh"功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7684441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com