Stop a UITableView from automatically scrolling

[亡魂溺海] 提交于 2019-12-19 11:45:12

问题


I have a UITableView that I'm autoscrolling with setContentOffset. Like so:

 CGFloat point = self.table.tblMinutes.contentSize.height - self.table.tblMinutes.bounds.size.height;

    [self.table.tblMinutes setContentOffset:CGPointMake(0, point) animated:false];
    [self.table.tblMinutes layoutIfNeeded];

    [UIView animateWithDuration:20.0 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        [self.table.tblMinutes setContentOffset:CGPointMake(0, point - 500) animated:false];
    } completion:nil];

What I want to achieve is for the scrolling to smoothly slow down and stop. I haven't been able to achieve that.

Calling [self.table.tblMinutes.layer removeAllAnimations] stops the animation, but moves the contentOffset for some reason, not achieving what I want.

I tried using the UIViewAnimationOptionBeginFromCurrentState option in a animation but that did nothing.

Any suggestions?


回答1:


This is a subset of the classic problem of interrupting an existing animation and replacing it with a different animation.

The problem here is that if you merely remove the existing animation, you will jump to the end of that animation.

The solution to that is to consult the presentation layer and set the layer to that position before removing the existing animation. Now you are starting from midstream and can apply another animation.




回答2:


Take a look at Kyle Truscott's excellent blog post about this for UIScrollView. UITableView inherits from UIScrollView, so in theory, it should work.



来源:https://stackoverflow.com/questions/33766993/stop-a-uitableview-from-automatically-scrolling

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