阻止 UITableView 自动滚动

Stop a UITableView from automatically scrolling(阻止 UITableView 自动滚动)
本文介绍了阻止 UITableView 自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个使用 setContentOffset 自动滚动的 UITableView.像这样:

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 自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中设置滚动视图内容大小)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 并为 iOS 5 Target 构建会导致 UIScrollView setMinimumZoomScale 失败) -
Create partial-screen UIPageViewController programmatically(以编程方式创建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中缩放和捏合)