以编程方式强制 UIScrollView 停止滚动,以便与多个

Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources(以编程方式强制 UIScrollView 停止滚动,以便与多个数据源共享表格视图)
本文介绍了以编程方式强制 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 停止滚动,以便与多个数据源共享表格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
quot;Server certificate untrustedquot; error in iPhone application(“服务器证书不受信任iPhone应用程序中的错误)
Comparing an NSDate to [NSDate date](将 NSDate 与 [NSDate 日期] 进行比较)