以编程方式强制UIScrollView停止滚动,以共享具有多个数据源的表视图 [英] Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources

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

问题描述

我有一个UITableView,当用户触摸分段控件(在应用商店应用中为热门付费和热门免费)时,其数据源和代理在两个自定义数据源对象之间切换。



每个数据源对象保存其最后一个滚动内容偏移量,并通过执行以下操作将其恢复为表视图的活动数据源:

  tableView.contentOffset = CGPointMake(0,savedScrollPosition); 

当用户在休息时切换数据源时,在表仍在移动(即减速)的同时击中分段控件,表视图继续从旧偏移减速,有效地覆盖我的contentOffset赋值。



当我设置contentOffset或另一种方式使这种类型的可切换数据源表视图工作时,强制表视图停止滚动/减速?



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

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

或:

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

它们应该实际上影响滚动和扩展表的加速度,而不仅仅是可见的


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);

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.

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?

解决方案

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];

OR:

[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停止滚动,以共享具有多个数据源的表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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