橡皮筯式下拉刷新控件的实现,效果超赞(OC版本)

本刷新控制支持两种形式,默认是橡皮筯式,也是QQ上见到的效果,皮筯拉到一定的长度,自动进入刷新状态; 另外一种是常见形式(下拉可以刷新,松手即将刷新,正在刷新),大家可以根据自己喜欢切换。

效果图如下

默认QQ皮筋效果



原味效果


原本MJRefresh

    self.collectionV.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewTopics)];
    self.collectionV.mj_header.automaticallyChangeAlpha = YES;
    [self.collectionV.mj_header beginRefreshing];


创建说明
@property (nonatomic ,weak) TGRefreshOC *refresh;
//换用自己的刷新控件,更多灵活配置
    TGRefreshOC *refresh = [TGRefreshOC new];
//    refresh.kind = RefreshKindNormal;//如果需要原味模式,由写此句,不写此句,就是QQ皮筯模式
    //refresh.bgColor =  [UIColor colorWithWhite:0.8 alpha:1];//自定义背景色
    refresh.verticalAlignment = TGRefreshAlignmentMidden;//垂直对齐方式
    refresh.automaticallyChangeAlpha = YES;//自动透明
    refresh.refreshResultTextColor = [UIColor whiteColor];//刷新结果字体颜色
    refresh.refreshResultBgColor = [[UIColor redColor] colorWithAlphaComponent:0.6];//刷新结果背景色
    [self.collectionV addSubview:refresh];
    _refresh = refresh;
    [refresh addTarget:self action:@selector(loadNewTopics) forControlEvents:UIControlEventValueChanged];
    [refresh beginRefreshing];//需要马上进入刷新模式则写此句,一般用于一进入界面加载数据


更多配置说明,如需要自定义各种状态的文字等

@property(nonatomic,assign) TGRefreshKind kind;//类型,默认为QQ
@property(nonatomic,strong) UIColor * bgColor;//背景色
@property(nonatomic,strong) UIColor * tinColor;//主题色(刷新文字颜色、ActivityIndicator颜色、橡皮筯颜色)
@property(nonatomic,assign) TGRefreshAlignment verticalAlignment;//垂直对齐,默认顶部
@property(nonatomic,copy) NSString * refreshSuccessStr;//刷新成功
@property(nonatomic,copy) NSString * refreshNormalStr;//准备刷新
@property(nonatomic,copy) NSString * refreshPullingStr;//即将刷新
@property(nonatomic,copy) NSString * refreshingStr;//正在刷新

@property(nonatomic,copy) NSString * refreshResultStr;//更新结果
@property(nonatomic,strong) UIColor * refreshResultBgColor;//更新结果的背景色
@property(nonatomic,strong) UIColor * refreshResultTextColor;//更新结果的文字颜色
@property(nonatomic,assign) CGFloat refreshResultHeight;//更新结果的高度

@property(nonatomic,assign) BOOL automaticallyChangeAlpha;//自动改变透明度

调用示例

- (void)loadNewTopics{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    self.params = parameters;
    TGNetworkTools *tools = [TGNetworkTools sharedTools];
    [tools request:GET urlString:[self requesturl:@"0"] parameters:parameters finished:^(id responseObject, NSError * error) {
        _np = responseObject[@"info"][@"np"];
        self.topics = [TGTopicNewM mj_objectArrayWithKeyValuesArray:responseObject[@"list"]];
        self.refresh.refreshResultStr = [NSString stringWithFormat:@"成功刷新到%zd条数据",self.topics.count];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.refresh endRefreshing];
        });
        [self.collectionV reloadData];
    }];


主要代码

//
//  TGRefreshOC.m
//  baisibudejie
//
//  Created by targetcloud on 2017/6/19.
//  Copyright © 2017年 targetcloud. All rights reserved.
//

#import "TGRefreshOC.h"

#define kBeginHeight 40.0//启始高度
#define kDragHeight 90.0//拖拽高度
#define kCenter CGPointMake(self.bounds.size.width * 0.5, kBeginHeight * 0.5)//启始圆心
#define kRadius 15.0//启始半径

typedef NS_ENUM(NSInteger, TGRefreshState) {
    RefreshStateNormal,
    RefreshStatePulling,
    RefreshStateRefresh,
};

@interface TGRefreshOC()
@property (assign ,nonatomic) CGFloat deltaH;
@property (weak, nonatomic) UIScrollView *sv;
@property (weak, nonatomic) UIActivityIndicatorView *activityIndicatorView;
@property (strong
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值