Adam Carter
Adam Carter

Reputation: 4844

using the scrollViewWillEndDragging:withVelocity:targetContentOffset on a UITableView

I have tried to use scrollViewWillEndDragging:withVelocity:targetContentOffset on my UITableView so when I reach a certain place, i.e. a hidden segmented control at the top of the table, it will then decelerate to the top of the segmented control 'sticking' it to the underneath of the navigation bar.

I have the following code:

- (CGPoint)tableOffsetForProposedOffset:(CGPoint)proposedOffset currentOffset:(CGPoint)currentOffset {
    NSLog(@"Current:  %@", NSStringFromCGPoint(currentOffset));
    NSLog(@"Before:   %@", NSStringFromCGPoint(proposedOffset));

    if (currentOffset.y <= -10) {
        // Show segmented control
        NSLog(@"--- Show ---");
        proposedOffset.y -= 500;
    } else if (currentOffset.y >= 42) {
        // Hide segmented control
    }

    NSLog(@"Proposed: %@", NSStringFromCGPoint(proposedOffset));

    return proposedOffset;
}

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    *targetContentOffset = [self tableOffsetForProposedOffset:*targetContentOffset currentOffset:scrollView.contentOffset];

    NSLog(@"Returned: %@", NSStringFromCGPoint(*targetContentOffset));
}

Please note that I am only using '500' to test with

All of my logs show the correct details, and most importantly, the 'Returned' *targetContentOffset it correct too. i.e. Returned: {0, -458}.

What can I possibly be doing wrong?

Thanks in advance for any help!

Upvotes: 1

Views: 1323

Answers (1)

stigi
stigi

Reputation: 6721

I'm not 100% certain (as the documentation also is very reserved about that) but I think that if *targetContentOffset is bigger than the maximum content offset the value will be ignored.

Upvotes: 3

Related Questions