本刷新控制支持两种形式,默认是橡皮筯式,也是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