Fire Fist
Fire Fist

Reputation: 7050

How to detect UITableView scrolling down only in iOS?

Now i can detect UITableView Scrolling Up and Down with following code.

However i only want to fire event when scrolling down. Not including Upper Scrolling.

In - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate with these codes

NSInteger currentOffset = scrollView.contentOffset.y;
    NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;

if (maximumOffset - currentOffset <= 20.0) {
        //        [self methodThatAddsDataAndReloadsTableView];

How to detect only for scrolling down to the bottom in UITableView.

Upvotes: 1

Views: 2752

Answers (1)

vokilam
vokilam

Reputation: 10313

You can compare current contentOffset with target contentOffset when dragging will end. Or check scrolling velocity sign:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView 
                     withVelocity:(CGPoint)velocity 
              targetContentOffset:(inout CGPoint *)targetContentOffset {
    NSLog(@"%@", scrollView.contentOffset.y > targetContentOffset->y ? @"top" : @"bottom");
    NSLog(@"%@", velocity.y > 0 ? @"bottom" : @"top");
}

Upvotes: 2

Related Questions