Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

ios - Detecting the bottom "bounce" of UITableView

I have a table view that performs an animation when the user scrolls down on a UITableView (push thumb up) and a different animation when the user scrolls up (Push thumb down) on a UITableView.

The problem is when the user reaches the bottom of a UITableView and it bounces, the table registers an upward and then downward movement, thus performing the animation when it should not.

This same exact behavior happens when scrolling to the top; however, I am able to detect it like so:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

    self.lastContentOffset = scrollView.contentOffset;

}


-(void) scrollViewDidScroll:(UIScrollView *)scrollView {

    // Check if we are at the top of the table
    // This will stop animation when tableview bounces

    if(self.tableView.contentOffset.y < 0){
        // Dont animate, top of tableview bounce


    } else {

        CGPoint currentOffset = scrollView.contentOffset;

        if (currentOffset.y > self.lastContentOffset.y) {

            // Downward animation
            [self animate:@"Down"];

        } else {

            // Upward
            [self animate:@"Up"];

        }

        self.lastContentOffset = currentOffset;

    }

}

This works perfectly, but for the life of me I cannot figure out an if condition to detect the bottom as well. I am sure it is simple and I just cant figure it out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How about something like this:

if (self.tableView.contentOffset.y >= (self.tableView.contentSize.height - self.tableView.bounds.size.height)) 
{
    // Don't animate
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...