博客> 源码剖析--SVPullToRefresh
源码剖析--SVPullToRefresh
2018-10-21 12:00 评论:0 阅读:1088 火之玉
ios 源码 SVPullToRefresh

阅读源码之路终于开启了, 小白一枚, 大神们要多多照顾啊, 有什么建议可以评论或私信, 在此多谢了!!!!

原文: http://www.jianshu.com/p/05afbf321675


概要

文件结构

文章目录
  • 前言
  • API说明
  • 原理解析
  • 总结

1.前言

作为一个刷新框架, SVPullToRefresh以其简洁, 通俗易懂为大家所推崇. 对于刚开始读源码的我来说, 再合适不过了, 而且最近正在做一个刷新demo, 用到, 顺便整理一下, 学习学习. SV是个熟悉的前缀, 就算没听过SVPullToRefresh, 也听过SVProgressHUD吧. 除了这些, 作者Sam还有其他优秀的开源代码, 大家感兴趣可以看看.


2.API说明

2.1 下拉刷新

下拉刷新ScrollView

@class SVPullToRefreshView;
@interface UIScrollView (SVPullToRefresh)

typedef NS_ENUM(NSUInteger, SVPullToRefreshPosition) {
    SVPullToRefreshPositionTop = 0,
    SVPullToRefreshPositionBottom,
};

//默认添加方法, position为top
- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler;

/*
  自定义添加下拉刷新的方法, 可以改变刷新方式; 
  top为下拉刷新, bottom为上拉刷新;
*/
- (void)addPullToRefreshWithActionHandler:(void (^)(void))actionHandler position:(SVPullToRefreshPosition)position;

//触发一次刷新, 会执行handler这个block里面的方法
- (void)triggerPullToRefresh;

//下拉刷新视图
@property (nonatomic, strong, readonly) SVPullToRefreshView *pullToRefreshView;

//是否展示下拉刷新视图(须在addPullToRefreshWithActionHandler:方法后面)
@property (nonatomic, assign) BOOL showsPullToRefresh;

@end

下拉刷新View

//只保留可更改选项

@interface SVPullToRefreshView : UIView
//下拉刷新箭头颜色
@property (nonatomic, strong) UIColor *arrowColor;
//文本颜色
@property (nonatomic, strong) UIColor *textColor;
//指示器view颜色
@property (nonatomic, strong, readwrite) UIColor *activityIndicatorViewColor NS_AVAILABLE_IOS(5_0);
//指示器类型
@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;

//根据刷新状态设置标题
- (void)setTitle:(NSString *)title forState:(SVPullToRefreshState)state;
//根据刷新状态设置副标题
- (void)setSubtitle:(NSString *)subtitle forState:(SVPullToRefreshState)state;
//根据刷新状态设置自定义View
- (void)setCustomView:(UIView *)view forState:(SVPullToRefreshState)state;

//开始动画
- (void)startAnimating;
//结束动画
- (void)stopAnimating;

//最后更新日期(NSDate)
@property (nonatomic, strong) NSDate *lastUpdatedDate DEPRECATED_ATTRIBUTE;
//日期格式(NSDateFormatter)
@property (nonatomic, strong) NSDateFormatter *dateFormatter DEPRECATED_ATTRIBUTE;

@end 
收藏
1
sina weixin mail 回到顶部