scrollViewDidScroll: on UITableViewRowAnimation?

谁都会走 提交于 2019-12-23 12:04:20

问题


When one uses a UITableViewRowAnimation upon deletion of a row or the addition of a row, sometimes if this row is at the extremes of the tableview the table scrolls.

Yet, even though it scrolls it doesn't seem to call scrollViewDidScroll: on the delegate.

For example, I have the following code in my delegate.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"Scrolling %f", scrollView.contentOffset.y);
}

Which gets called if the user scrolls. But when I have a deletion of a row:

[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

The scrollViewDidScroll: method is not called at all.

Is there any way to ensure that this gets called while the UITableView is animating?

Thanks!


回答1:


In case you weren't aware, scrollViewDidScroll is only called in response to user interaction with a scroll view (or, in this case, table view). It is not called in response to scrolling due to animations. This behavior is fixed. You'll need to find another way to achieve what you're after. Perhaps this existing question might be of use:

How to make UIScrollView send scrollViewDidScroll messages during animations




回答2:


You can use the following approach instead.

    [CATransaction setCompletionBlock: ^{
        // do stuff
    }];

    [CATransaction begin];

    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];

    [CATransaction commit];


来源:https://stackoverflow.com/questions/22648168/scrollviewdidscroll-on-uitableviewrowanimation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!