Generally speaking of pull-up refresh drop-down refresh, many people may think of a third-party open source framework Egorefresh, below, how to write their own code implementation.
UITableView itself is a uiscrollview, so uitableview can implement Uiscrollview proxy method. Pull and drop-down refreshes are nothing more than a uiscrollview offset to a certain extent called the Refresh method. Implementation-(void) Scrollviewdidscroll: (uiscrollview*) ScrollView proxy method. The code is as follows:
(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 假设偏移表格高度的20%进行刷新
if
(!_isLoading) {
// 判断是否处于刷新状态,刷新中就不执行
// 取内容的高度:
// 如果内容高度大于UITableView高度,就取TableView高度
// 如果内容高度小于UITableView高度,就取内容的实际高度
float
height = scrollView.contentSize.height > _tableView.frame.size.height ?_tableView.frame.size.height : scrollView.contentSize.height;
if
((height - scrollView.contentSize.height + scrollView.contentOffset.y) / height > 0.2) {
// 调用上拉刷新方法
}
if
(- scrollView.contentOffset.y / _tableView.frame.size.height > 0.2) {
// 调用下拉刷新方法
}
}
}
IOS Pull-down refresh simple implementation code