利用scrollView滑动的2个监听方法实现
//滑动结束时候 出发的方法
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
if (self.refreshLabel.tag == 1) {
[UIView animateWithDuration:.3 animations:^{
// [self searchSevicePushData];
self.refreshLabel.text = @"加载中...";
scrollView.contentInset = UIEdgeInsetsMake(80.0f, 0.0f, 0.0f, 0.0f);
}];
//数据加载成功后执行;这里为了模拟加载效果,一秒后执行恢复原状代码
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadSexButton];
[UIView animateWithDuration:.3 animations:^{
self.refreshLabel.tag = 0;
self.refreshLabel.text = @"下拉刷新";
scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}];
});
}
}
//滑动过程中的监听方法
#pragma mark -UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// NSLog(@"滑动%f",scrollView.contentOffset.y);
if (scrollView.contentOffset.y <= -70)
{
// CGFloat y = fabs(scrollView.contentOffset.y);
// NSLog(@"%f",y);
if (self.refreshLabel.tag == 0) {
self.refreshLabel.text = @"松开刷新";
}
self.refreshLabel.tag = 1;
}else{
//防止用户在下拉到contentOffset.y <= -50后不松手,然后又往回滑动,需要将值设为默认状态
self.refreshLabel.tag = 0;
self.refreshLabel.text = @"下拉刷新";
}
}