#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){code
/** * 發起網絡請求,請求刷新數據 */ [_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+++++++++++++++++++上拉加載原理+++++++++++++++++++animation
(void)scrollViewDidEndDragging:(UIScrollView )scrollView willDecelerate:(BOOL)decelerate { NSLog(@"%f",scrollView.contentOffset.y); NSLog(@"%f",scrollView.frame.size.height); NSLog(@"%f",scrollView.contentSize.height); /*it
關鍵-->io
scrollView一開始並不存在偏移量,可是會設定contentSize的大小,因此contentSize.height永遠都會比contentOffset.y高一個手機屏幕的table
高度;上拉加載的效果就是每次滑動到底部時,再往上拉的時候請求更多,那個時候產生的偏移量,就能讓contentOffset.y + 手機屏幕尺寸高大於這原理
個滾動視圖的contentSize.height */ if (scrollView.contentOffset.y + scrollView.frame.size.height >= scrollView.contentSize.height) { NSLog(@"%d %s",LINE,FUNCTION); [UIView commitAnimations];List
[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;request
}];
}];請求
} }