#pragma mark+++++++++++++++++++下拉刷新原理+++++++++++++++++++
-
(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { NSLog(@"scrollViewX:%f scrollViewY:%f",scrollView.contentOffset.x ,scrollView.contentOffset.y); if (scrollView.contentOffset.y <-60) { [UIView animateWithDuration:0.2 animations:^{ self.allTableView.contentInset = UIEdgeInsetsMake(40.0f, 0.0f, 0.0f, 0.0f); } completion:^(BOOL finished){
/** * 发起网络请求,请求刷新数据 */ [_dataSource requestListAllData:^(NSArray *array) { _allDataSource = [[NSMutableArray alloc]initWithArray:array]; //刷新 [_allTableView reloadData]; self.pag=2; [UIView animateWithDuration:0.2 animations:^{ self.allTableView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f); }]; }]; }];
} } #pragma mark+++++++++++++++++++上拉加载原理+++++++++++++++++++
-
(void)scrollViewDidEndDragging:(UIScrollView )scrollView willDecelerate:(BOOL)decelerate { NSLog(@"%f",scrollView.contentOffset.y); NSLog(@"%f",scrollView.frame.size.height); NSLog(@"%f",scrollView.contentSize.height); /*
-
关键-->
-
scrollView一开始并不存在偏移量,但是会设定contentSize的大小,所以contentSize.height永远都会比contentOffset.y高一个手机屏幕的
-
高度;上拉加载的效果就是每次滑动到底部时,再往上拉的时候请求更多,那个时候产生的偏移量,就能让contentOffset.y + 手机屏幕尺寸高大于这
-
个滚动视图的contentSize.height */ if (scrollView.contentOffset.y + scrollView.frame.size.height >= scrollView.contentSize.height) { NSLog(@"%d %s",LINE,FUNCTION); [UIView commitAnimations];
[UIView animateWithDuration:1.0 animations:^ { //frame发生的偏移量,距离底部往上提高60(可自行设定) self.allTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); } completion:^(BOOL finished) { __weak typeof(self) weakSelf = self; [_dataSource addListAllDataWithPag:weakSelf.pag Data:^(NSArray *array) { [weakSelf.allDataSource addObjectsFromArray:array]; [weakSelf.allTableView reloadData]; weakSelf.pag+=1;
}];
}];
} }
-