以编程方式强制 UIScrollView 停止滚动,以便与多个数据源共享表格视图

时间:2022-10-27
本文介绍了以编程方式强制 UIScrollView 停止滚动,以便与多个数据源共享表格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 UITableView,当用户触摸分段控件时,它的数据源和委托在几个自定义数据源对象之间切换(想想应用商店应用中的Top Paid"与Top Free").

I have a UITableView whose data source and delegate are switched between a couple of custom data source objects when the user touches a segmented control (think "Top Paid" vs "Top Free" in the app store app).

每个数据源对象保存它的最后滚动内容偏移量,并在它成为表格视图的活动数据源时恢复它,方法是:

Each data source object saves its last scroll content offset, and restores it when it becomes the active data source for the table view by doing:

tableView.contentOffset = CGPointMake(0, savedScrollPosition);

这在用户在表格静止时切换数据源时效果很好,但是如果用户在表格仍在移动(即减速)时点击分段控件,表格视图会继续从旧的偏移量开始减速,有效地覆盖我的 contentOffset 分配.

This works well when the user switches the data source when the table is at rest, but if the user hits the segmented control while the table is still moving (i.e. decelerating), the table view continues to decelerate from the old offset, effectively overriding my contentOffset assignment.

有没有办法在我设置 contentOffset 时强制表格视图停止滚动/减速,或者有其他方法使这种类型的可切换数据源表格视图工作?

Is there a way to force the table view to stop scrolling/decelerating when I set the contentOffset, or another way to make this type of switchable-data-source table view work?

推荐答案

这2个方法你试过了吗?

Did you try these 2 methods?

它们实际上适用于滚动",而不仅仅是内容的偏移量.

They actually apply to the "scrolling" not just the offset of the content.

[self.tableView  scrollToRowAtIndexPath:savedIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

或者:

[self.tableView  scrollRectToVisible:savedFrame animated:NO];

它们实际上应该影响滚动并通过扩展来加速表格,而不仅仅是屏幕上可见的内容.

They should actually effect the scrolling and by extension the acceleration of the table, not just what is visible on screen.

这篇关于以编程方式强制 UIScrollView 停止滚动,以便与多个数据源共享表格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一条:Xcode &Swift - 在 UIScrollView 内检测 UIView 的用户触摸 下一条:如何使用计时器自动滚动 UIScrollView?

相关文章

最新文章