我有一个表视图,当用户向下滚动UITableView(按下拇指向上)时执行动画,当用户在UITableView上向上滚动(按下拇指向下)时,执行不同的动画.
问题是当用户到达UITableView的底部并且它反弹时,表会记录向上然后向下移动,从而在不应该执行时执行动画.
滚动到顶部时会发生同样的确切行为;但是,我能够像这样检测它:
- - (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;
- }
- }
这很完美,但对于我的生活,我无法找出检测底部的if条件.我确信它很简单,我只是想不通.
解决方法
这样的事情怎么样:
- if (self.tableView.contentOffset.y >= (self.tableView.contentSize.height - self.tableView.bounds.size.height))
- {
- // Don't animate
- }