//
// ViewController.m
// Refresh
//
// Created by Apple on 16/7/19.
// Copyright © 2016年 mac. All rights reserved.
// #import "ViewController.h"
#import "MJRefresh.h"
#import "DIYRefreshHeader.h" @interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSArray *dataArr;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; _dataArr = @[@"",@"",@"",@"",@"",@"",@"",@"",@"",@""];
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self; [self.view addSubview:_tableView]; // 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
self.tableView.mj_header = [DIYRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
[self.tableView.mj_header beginRefreshing];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArr.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *str = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
}
cell.textLabel.text = _dataArr[indexPath.row];
return cell;
} #pragma mark - 数据处理相关
#pragma mark 下拉刷新数据
- (void)loadNewData { } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// DIYBackFooter.m
// Refresh
//
// Created by Apple on 16/7/20.
// Copyright © 2016年 mac. All rights reserved.
// #import "DIYBackFooter.h" @interface DIYBackFooter () @property (weak, nonatomic) UILabel *lable;
@property (weak, nonatomic) UIImageView *logoImg;
@property (weak, nonatomic) UIImageView *loadingImg; @end
//在DIYBackFooter 这个类中,自定义
@implementation DIYBackFooter #pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置(比如添加子控件) - (void)prepare { [super prepare]; //设置控件的高度
self.mj_h = 60.0f; //添加 lable UILabel *lable = [[UILabel alloc] init];
lable.font = [UIFont boldSystemFontOfSize:10.0f];
lable.textAlignment = NSTextAlignmentCenter;
[self addSubview:lable];
self.lable = lable; //logo
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading_logo.png"]];
[self addSubview:logo];
self.logoImg = logo;
//loadingImg
UIImageView *loading = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading_logo_round"]];
[self addSubview:loading];
self.loadingImg = loading; } #pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews { [super placeSubviews]; self.logoImg.frame = CGRectMake(, , 26.0f, 26.0f);
self.logoImg.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5 - 10.0f); self.loadingImg.frame = CGRectMake(, , 36.0f, 36.0f);
self.loadingImg.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5 - 10.0f); self.lable.frame = CGRectMake(self.mj_w * 0.5 - 40.0f, self.mj_h - 15.0f, 80.0f, 12.0f); } #pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
[super scrollViewContentOffsetDidChange:change]; } #pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
[super scrollViewContentSizeDidChange:change]; } #pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
[super scrollViewPanStateDidChange:change]; } #pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
MJRefreshCheckState; switch (state) {
case MJRefreshStateIdle: {
[self.loadingImg stopAnimating];
self.lable.text = @"下拉刷新";
}
break;
case MJRefreshStatePulling: { [self.loadingImg stopAnimating];
self.lable.text = @"松开刷新";
[self isAnimation];
}
break;
case MJRefreshStateRefreshing: { self.lable.text = @"正在刷新";
[self isAnimation];
[self.loadingImg startAnimating];
}
break;
default:
break;
}
} - (void)isAnimation { CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI];
rotationAnimation.duration = * 0.075;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = ; [self.loadingImg.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; } #pragma mark 监听拖拽比例(控件被拖出来的比例)
- (void)setPullingPercent:(CGFloat)pullingPercent { [super setPullingPercent:pullingPercent];
} @end

使用 MJ 自定义下拉刷新的更多相关文章

  1. Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)

    PullToRefreshScrollView 自定义下拉刷新动画,只需改一处. 以下部分转载自http://blog.csdn.net/superjunjin/article/details/450 ...

  2. 使用MJRefresh自定义下拉刷新,上拉加载动画

    有时候我们需要自己设置下拉刷新,上拉加载动画的实现,这里主要是记录下使用MJRefresh自定义下拉刷新,上拉加载动画..... 下拉刷新我们只需要继承MJRefreshGifHeader即可: 实现 ...

  3. Android自定义下拉刷新

    网上的下拉刷新功能很多,不过基本上都是隐藏header的,而项目里面需要只隐藏部分的header,类似QQ好友动态的效果,修改了一些现有的,最后有很多问题,所以就自己自定义了一个,逻辑也很简单,首先就 ...

  4. 微信小程序-自定义下拉刷新

    最近给别个公司做技术支持,要实现微信小程序上拉刷新与下拉加载更多 微信给出的接口不怎么友好,最终想实现效果类似QQ手机版 ,一共3种下拉刷新状态变化,文字+图片+背景颜色 最终实现后的效果(这里提示有 ...

  5. 使用 CSS overscroll-behavior 控制滚动行为:自定义下拉刷新和溢出效果

    CSS 的新属性 overscroll-behavior 允许开发者覆盖默认的浏览器滚动行为,一般用在滚动到顶部或者底部. 背景 滚动边界和滚动链接(boundary & chaining) ...

  6. 自定义下拉刷新控件-CBStoreHouseRefreshControl

    本文转载至 http://www.cocoachina.com/ios/20141110/10177.html iOS开发自定义刷新CBStoreHouseRefres 介绍 这是一款在Storeho ...

  7. Android 自定义下拉刷新ListView

    package com.dwtedx.qq.view; import android.content.Context; import android.util.AttributeSet; import ...

  8. 自定义下拉刷新上拉加载View

    MainActivity.java package com.heima52.pullrefresh; import java.util.ArrayList; import com.heima52.pu ...

  9. react-native 自定义 下拉刷新 / 上拉加载更多 组件

    1.封装 Scroller 组件 /** * 下拉刷新/上拉加载更多 组件(Scroller) */ import React, {Component} from 'react'; import { ...

随机推荐

  1. nodejs+express +jade模板引擎 新建项目

    先 安装 nodejsiDEAAM 2015/7/16 22:47:25然后安装 npm install expressiDEAAM 2015/7/16 22:47:35然后安装 npm instal ...

  2. RabbitMQ (三) 发布/订阅 -摘自网络

    这篇博客中,我们会做一些改变,就是把一个消息发给多个消费者,这种模式称之为发布/订阅(类似观察者模式). 为了验证这种模式,我们准备构建一个简单的日志系统.这个系统包含两类程序,一类程序发动日志,另一 ...

  3. 第三百零四天 how can I 坚持

    我以为我遇到了,却是痴心妄想啊.哪有那么好的事.其实也无所谓,淡定,却又有点不淡定了. 洗澡睡觉吧,明天还要上班呢. 应该摆脱这种状态. 什么都不想,放空.

  4. source insight 支持CC 文件

    今天开始阅读LevelDB的代码,用source insight建立工程,但其不支持cc后缀的C++文件. 找到这篇<source insight看cc文件> 解决的根本办法:Option ...

  5. 在Delphi7中JSON遍历节点不支持使用IN处理方法

    相关资料:http://www.cnblogs.com/del/archive/2009/10/23/1588690.html Delphi2007源代码: procedure TForm1.Butt ...

  6. POJ 1751 Highways (最小生成树)

    Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...

  7. My97DatePicker的calendar.js的反混淆

    eval(string)函数 <script> eval(function(p, a, c, k, e, d) { p = 'function p(){console.log(" ...

  8. 使用gson进行json转换

    Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. 示例代码如下: 实体定义 ...

  9. thymeleaf中的th:each用法

    一.th:eath迭代集合用法: <table> <thead> <tr> <th>序号</th> <th>用户名</th ...

  10. [iOS基础控件 - 6.12.4] NavigationController vs TabBarController

    A.属性 1. Item NavigationController: navigationItem (不需要创建) title rightBarButtonItems/ rightBarButtonI ...