feat:optimize refreshable

This commit is contained in:
pengfei.zhou 2019-11-27 19:57:43 +08:00
parent 8b1ed0acc8
commit 459aab61e3
2 changed files with 19 additions and 9 deletions

View File

@ -76,23 +76,24 @@ - (void)setHeaderView:(UIView *)headerView {
self.refreshable = YES; self.refreshable = YES;
} }
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (-scrollView.contentOffset.y >= self.headerView.height) { if (-scrollView.contentOffset.y >= self.headerView.height) {
dispatch_async(dispatch_get_main_queue(), ^{
self.refreshing = YES; self.refreshing = YES;
});
} }
} }
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y <= 0) { if (scrollView.contentOffset.y <= 0) {
[self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height]; [self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height];
//self.bounces = YES;
} else {
//self.bounces = NO;
//scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
} }
} }
- (void)setContentOffset:(CGPoint)contentOffset {
[super setContentOffset:contentOffset];
}
- (void)setRefreshing:(BOOL)refreshing { - (void)setRefreshing:(BOOL)refreshing {
if (_refreshing == refreshing) { if (_refreshing == refreshing) {
return; return;
@ -101,21 +102,26 @@ - (void)setRefreshing:(BOOL)refreshing {
if (self.onRefreshBlock) { if (self.onRefreshBlock) {
self.onRefreshBlock(); self.onRefreshBlock();
} }
[UIView animateWithDuration:0.3f [UIView animateWithDuration:.3f
animations:^{ animations:^{
self.contentOffset = (CGPoint) {0, -self.headerView.height};
self.contentInset = UIEdgeInsetsMake(self.headerView.height, 0, 0, 0); self.contentInset = UIEdgeInsetsMake(self.headerView.height, 0, 0, 0);
} }
completion:^(BOOL finished) { completion:^(BOOL finished) {
[self.swipePullingDelegate startAnimation]; [self.swipePullingDelegate startAnimation];
self.scrollEnabled = NO;
} }
]; ];
} else { } else {
[UIView animateWithDuration:0.3f self.bounces = YES;
[UIView animateWithDuration:.3f
animations:^{ animations:^{
self.contentOffset = (CGPoint) {0, 0};
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
} }
completion:^(BOOL finished) { completion:^(BOOL finished) {
[self.swipePullingDelegate stopAnimation]; [self.swipePullingDelegate stopAnimation];
self.scrollEnabled = YES;
} }
]; ];
} }
@ -124,6 +130,10 @@ - (void)setRefreshing:(BOOL)refreshing {
- (void)setRefreshable:(BOOL)refreshable { - (void)setRefreshable:(BOOL)refreshable {
self.scrollEnabled = refreshable; self.scrollEnabled = refreshable;
if (refreshable) {
self.contentOffset = (CGPoint) {0, 0};
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
} }
- (BOOL)refreshable { - (BOOL)refreshable {