Objective C: Detect start of bouncing effect for UIScrollView

For detect bouncing of UIScrollView (or UITableView ...) using UIScrollViewDelegate:
static BOOL _draggingView = NO;

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
 _draggingView = YES;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
 _draggingView = NO;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 NSInteger pullingDetectFrom = 50;
 if (self.contentOffset.y < -pullingDetectFrom) {
  _draggingView = NO;
  NSLog(@"Pull Down");
 } else if (self.contentSize.height <= self.frame.size.height && self.contentOffset.y > pullingDetectFrom) {
  _draggingView = NO;
  NSLog(@"Pull Up");
 } else if (self.contentSize.height > self.frame.size.height && 
       self.contentSize.height-self.frame.size.height-self.contentOffset.y < -pullingDetectFrom) {
  _draggingView = NO;
  NSLog(@"Pull Up");
 }
}

3 comments: