Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources(以编程方式强制 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 停止滚动,以便与多个数据源共享表格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式强制 UIScrollView 停止滚动,以便与多个
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01