MSPullToRefreshController 1.1.0

MSPullToRefreshController 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可协议 MIT
发布最后发布2014年12月

未声明 维护。



  • 作者:
  • John Z Wu

Miso's Pull To Refresh 库 (相关博客文章)

作者

我和 Tim Lee

下拉刷新演示

我创建了一个简单的样例项目,该项目模拟了我们的熟悉的多彩加载数据到 uitableview 中的操作,该操作是同步的。

功能

  • 不会抢占你的 scrollview 的 delegate(侵入式),只观察 scrollview 的 contentOffset 属性(非侵入式)
  • 允许从四个方向刷新(下拉刷新,上拉加载更多?)

如何使用

注意,这个库只是抽象了刷新周期逻辑,需要开发者结合自定义视图创建一个完整、视觉上令人满意的解决方案。

只有一个构造函数

MSPullToRefreshController *ptrc = [[MSPullToRefreshController alloc] initWithScrollView:scrollView delegate:self];

作为代理,你必须实现这些方法来通知库你的特定刷新需求

/*
 * asks the delegate which refresh directions it would like enabled
 */
- (BOOL) pullToRefreshController:(MSPullToRefreshController *) controller canRefreshInDirection:(MSRefreshDirection)direction;

/*
 * inset threshold to engage refresh
 */
- (CGFloat) pullToRefreshController:(MSPullToRefreshController *) controller refreshableInsetForDirection:(MSRefreshDirection) direction;

/*
 * inset that the direction retracts back to after refresh started
 */
- (CGFloat) pullToRefreshController:(MSPullToRefreshController *)controller refreshingInsetForDirection:(MSRefreshDirection)direction;

你可以(出于你自己的最好利益)实现这些方法,以便根据你在刷新周期中的位置来转换你的自定义视图

/*
 * informs the delegate that lifting your finger will trigger a refresh
 * in that direction. This is only called when you cross the refreshable
 * offset defined in the respective MSInflectionOffsets.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller canEngageRefreshDirection:(MSRefreshDirection) direction;

/*
 * informs the delegate that lifting your finger will NOT trigger a refresh
 * in that direction. This is only called when you cross the refreshable
 * offset defined in the respective MSInflectionOffsets.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller didDisengageRefreshDirection:(MSRefreshDirection) direction;

/*
 * informs the delegate that refresh sequence has been started by the user
 * in the specified direction. A good place to start any async work.
 */
- (void) pullToRefreshController:(MSPullToRefreshController *) controller didEngageRefreshDirection:(MSRefreshDirection) direction;

注意,你必须手动结束任何方向的刷新周期

[ptrc finishRefreshingDirection:MSRefreshDirectionTop animated:NO];

你也可以以编程的方式在任何方向开始刷新周期

[ptrc startRefreshingDirection:MSRefreshDirectionTop animated:YES];

注意

如果 scrollview 的内容大小(严格)小于 scrollview 的框架面积,则此库将崩溃。开发者必须确保这一点。

许可协议

MSPullToRefreshController 可在 MIT 许可协议下使用。有关更多信息,请参阅 LICENSE 文件。