实现pull以刷新视图功能 [英] Implementing pull to refresh view feature

查看:106
本文介绍了实现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:


  1. 将您的视图嵌入 UIScrollView

  2. 将您的控制器设置为

  3. 在滚动视图中添加Pull To Refresh子视图,使其框架离屏幕顶部较远。 cfrectake(0,-30,320,30)。

  4. 实施<$ c $

  5. 实施 -scrollViewDidEndDragging:willDecelerate: 以在拖动结束时检查 scrollView.contentOffset 。如果超过您的刷新阈值,请刷新。

  1. Embed your view in a UIScrollView.
  2. Set your controller as the delegate of the scroll view.
  3. 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.
  4. Implement –scrollViewDidScroll: to update your "Pull to Refresh" view as the user is dragging.
  5. Implement –scrollViewDidEndDragging:willDecelerate: to check scrollView.contentOffset when the dragging ends. If it's beyond your threshold for refreshing, then do the refresh.

这篇关于实现pull以刷新视图功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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