SVPullToRefreshPlus 0.4.4.2

SVPullToRefreshPlus 0.4.4.2

测试已测试
语言语言 Objective-CObjective C
许可证 MIT
发布最后发布2017年11月

Scott Corscadden 维护。



  • Sam Vermette

这是一个分支仓库,因为原始的不再活跃。邀请提交代码。

SVPullToRefresh + SVInfiniteScrolling

这些 UIScrollView 分类使得向任何 UIScrollView(或其子类)添加下拉刷新和无限滚动功能变得非常简单。SVPullToRefresh 不依赖于代理和/或 UIViewController 的子类化,而是使用 Objective-C 运行时在 UIScrollView 中添加以下 3 个方法:

- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler;
- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler position:(SVPullToRefreshPosition)position;
- (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler;

安装

从 CocoaPods 安装

pod 'SVPullToRefresh' 添加到您的 Podfile 中或如果您喜欢冒险,请添加 pod 'SVPullToRefresh', :head

手动安装

注意:如果您的项目未使用 ARC,则必须将编译器标志 -fobjc-arc 添加到 Target Settings > Build Phases > Compile Sources 中的 UIScrollView+SVPullToRefresh.mUIScrollView+SVInfiniteScrolling.m

  • SVPullToRefresh/SVPullToRefresh 文件夹拖到您的项目中。
  • QuartzCore 框架添加到您的项目中。
  • 导入 UIScrollView+SVPullToRefresh.h 和/或 UIScrollView+SVInfiniteScrolling.h

使用方法

(请参阅 /Demo 中的示例 Xcode 项目)

添加下拉刷新

[tableView addPullToRefreshWithActionHandler:^{
    // prepend data to dataSource, insert cells at top of table view
    // call [tableView.pullToRefreshView stopAnimating] when done
}];

如果要程序化触发刷新(例如在 viewDidAppear: 中),可以使用以下方法

[tableView triggerPullToRefresh];

您可以通过设置 showsPullToRefresh 属性来暂时隐藏下拉刷新视图

tableView.showsPullToRefresh = NO;

自定义

以下属性和方法可以用于自定义下拉刷新视图

@property (nonatomic, strong) UIColor *arrowColor;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;

- (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state;
- (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state;
- (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state;

您可以通过滚动视图的 pullToRefreshView 属性访问这些属性。

例如,您可以使用以下方法设置 arrowColor 属性

tableView.pullToRefreshView.arrowColor = [UIColor whiteColor];

添加无限滚动

[tableView addInfiniteScrollingWithActionHandler:^{
    // append data to data source, insert new cells at the end of table view
    // call [tableView.infiniteScrollingView stopAnimating] when done
}];

如果您要在 viewDidAppear: 程序化地触发加载(例如),可以使用以下方法

[tableView triggerInfiniteScrolling];

您可以通过设置 showsInfiniteScrolling 属性来暂时隐藏无限滚动视图

tableView.showsInfiniteScrolling = NO;

自定义

以下方法可以用于自定义无限滚动视图

- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle;
- (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state;

您可以通过滚动视图的 infiniteScrollingView 属性访问这些属性。

原理上

SVPullToRefresh 通过添加新的公共方法和动态属性扩展了 UIScrollView

它通过键值观察跟踪滚动视图的 contentOffset

致谢

SVPullToRefresh 是由 Sam Vermette项目贡献者 共同带来的。如果您有任何功能建议或错误报告,请通过发送拉取请求或在 创建新问题 的方式提供帮助。如果您的项目中使用了 SVPullToRefresh,给予归属是很好的。

非常感谢 @seb_morelDemistifying the Objective-C runtime 演讲,它对这一项目非常有帮助。

感谢 Loren Brichter 发明下拉刷新功能。