RefreshControl 2.0.5

RefreshControl 2.0.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2015年7月

MochMoch Xiao 维护。



  • 作者
  • Moch

它看起来如何?

     

     

     

   

如何使用?

Podfile

pod 'RefreshControl'

项目

#import "UIScrollView+RefreshControl.h"

敏感风格

顶部RefreshControl

    __weak typeof(self) weakSelf = self;
    [self.tableView addTopRefreshControlUsingBlock:^{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
          // request for datas
    });
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
            [weakSelf.tableView topRefreshControlStopRefreshing];
        });
    } refreshControlPullType:RefreshControlPullTypeInsensitive refreshControlStatusType:RefreshControlStatusTypeText];

注意:在回调块中,您应该首先重新加载数据,然后停止 TopRefreshControl 动画,否则,您的内容焦点将移至顶部。

底部RefreshControl

    __weak typeof(self) weakSelf = self;
    [self.tableView addBottomRefreshControlUsingBlock:^{        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
          // request for datas
        });
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
            [weakSelf.tableView bottomRefreshControlStopRefreshing];
        });
    } refreshControlPullType:RefreshControlPullTypeSensitive refreshControlStatusType:RefreshControlStatusTypeText];

注意:在回调块中,您应该始终首先重新加载数据,然后停止 BottomRefreshControl 动画,否则,您的内容底部将始终移至屏幕底部。

初始化刷新

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView topRefreshControlStartInitializeRefreshing];
    });

无感风格 & 状态类型

typedef NS_ENUM(NSInteger, RefreshControlPullType) {
    RefreshControlPullTypeSensitive,
    RefreshControlPullTypeInsensitive
};

typedef NS_ENUM(NSInteger, RefreshControlStatusType) {
    RefreshControlStatusTypeTextAndArrow,
    RefreshControlStatusTypeText,
    RefreshControlStatusTypeArrow
};

通过刷新控制 pullsType 设置 RefreshControlPullTypeInsensitive

顶部RefreshControl

addTopRefreshControlUsingBlock:refreshControlPullType:refreshControlStatusType

底部RefreshControl

addBottomRefreshControlUsingBlock:refreshControlPullType:refreshControlStatusType

顺便说一句

您可以根据需要更改状态文本和颜色,加载动画的圆圈颜色和箭头颜色。

@property (nonatomic, strong) NSString *topRefreshControlPullToRefreshingText;
@property (nonatomic, strong) NSString *topRefreshControlPullReleaseToRefreshingText;

@property (nonatomic, strong) NSString *bottomRefreshControlPullToRefreshingText;
@property (nonatomic, strong) NSString *bottomRefreshControlPullReleaseToRefreshingText;

@property (nonatomic, strong) UIColor *statusTextColor;
@property (nonatomic, strong) UIColor *loadingCircleColor;
@property (nonatomic, strong) UIColor *arrowColor;

您可以为刷新失败设置状态文本

topRefreshControlRefreshFailureWithHintText:
bottomRefreshControlRefreshFailureWithHintText:

您可以自己处理触摸事件

addTouchUpInsideEventForTopRefreshControlUsingBlock:
addTouchUpInsideEventForBottomRefreshControlUsingBlock:

如果您不处理此事件,则在您触摸 RefreshControl 或再次拉动时,我们会重新刷新。当然,在您处理此事件后,如果还想刷新,请调用流程消息或再次拉动。

topRefreshControlResumeRefreshing
bottomRefreshControlResumeRefreshing