停止UITableView自动滚动 [英] Stop a UITableView from automatically scrolling

查看:655
本文介绍了停止UITableView自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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

有什么建议吗?

推荐答案

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

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.

这篇关于停止UITableView自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆