实现pull以刷新视图功能 [英] Implementing pull to refresh view feature
本文介绍了实现pull以刷新视图功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以在自定义视图控制器上实现pull-refresh功能吗?我的视图控制器不是一个表视图控制器,我想刷新这个视图拉下屏幕。
Can we implement pull to refresh feature on a custom view controller?. My view controller is not a table view controller and I want to refresh this view on pulling the screen down. How can I implement this feature?
推荐答案
简而言之,您需要执行以下操作:
In short, you need to do the following:
- 将您的视图嵌入
UIScrollView
。 - 将您的控制器设置为
- 在滚动视图中添加Pull To Refresh子视图,使其框架离屏幕顶部较远。 cfrectake(0,-30,320,30)。
- 实施<$ c $
- 实施
-scrollViewDidEndDragging:willDecelerate:
以在拖动结束时检查scrollView.contentOffset
。如果超过您的刷新阈值,请刷新。
- Embed your view in a
UIScrollView
. - Set your controller as the delegate of the scroll view.
- Add a "Pull To Refresh" subview to the scroll view such that its frame is off the top of the screen. Something like
CGRectMake(0, -30, 320, 30)
for a 30pt-tall indicator view. - Implement
–scrollViewDidScroll:
to update your "Pull to Refresh" view as the user is dragging. - Implement
–scrollViewDidEndDragging:willDecelerate:
to checkscrollView.contentOffset
when the dragging ends. If it's beyond your threshold for refreshing, then do the refresh.
这篇关于实现pull以刷新视图功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文