停止UITableView自动滚动

时间:2015-11-17 21:06:28

标签: ios uitableview uiscrollview ios-animations

我有一个UITableView,我使用setContentOffset进行自动滚动。像这样:

 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];

我想要实现的是滚动平滑减速和停止。我还没有实现这一目标。

调用[self.table.tblMinutes.layer removeAllAnimations]会停止动画,但出于某种原因移动了contentOffset,而没有达到我想要的效果。

我尝试在动画中使用UIViewAnimationOptionBeginFromCurrentState选项但没有做任何事情。

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

这是打断现有动画并用不同动画替换它的经典问题的一个子集。

这里的问题是,如果您删除现有动画,您将跳转到该动画的结尾。

解决方法是参考表示层并在删除现有动画之前将图层设置为该位置。 现在你从中游开始,可以应用另一个动画。

答案 1 :(得分:0)

请查看Kyle Truscott's excellent blog post有关UIScrollView的内容。 UITableView继承自UIScrollView,因此理论上它应该可以工作。