//
// 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. ubuntu14.04.03 vsftpd

    apt-get install vsftpd /etc/vsftpd.conf配置Example listen=YES anonymous_enable=NO local_enable=YES wri ...

  2. android - python 自动化测试 移动互联网 - SegmentFault

    android - python 自动化测试 移动互联网 - SegmentFault splinter

  3. 第二百八十七天 how can I 坚持

    终于把假请下来了,没有想象的那么复杂. 忘退车票了.明天应该有手续费了,现在又维护了,哎.10%的手续费了.7块钱,没了.希望不会白回去一趟啊. sql,group by  having .还是学不会 ...

  4. Linux里实用命令之添加行号、文本和语法高亮显示

    写在前面的话 本博主我,强烈建议,来看此博文的朋友们,都玩玩. 最好,在刚入门的时候呢,不加行号,不玩文本和语法高亮显示,以后会深有体会.磨炼自己! 步骤一:进入 /etc/virc配置文件 步骤二: ...

  5. jdk的wsimport方法实现webservice客户端调用服务

    1.配置好jdk环境,打开命令行,输入wsimport回车能看到很多该命令的参数, -s:要生成客户端代码的存储路径 -p:对生成的代码从新打包 这两个最常用. 在打开的命令行中输入:wsimport ...

  6. AVCaptureDevice的几个属性

    AVCaptureDevice.h,主要用来获取iphone一些关于相机设备的属性. AVCaptureDevice.h,必须要引入AVFoundation.framework包. 1. 前置和后置摄 ...

  7. 开发程序过程中遇到的调用Web Api小问题

    在用Umbraco Web Api开发程序时,前端使用React调用Web Api 当时是有一个页面Search.cshtml,把用React产生的脚本代码,在这个页面进行引用 写了一个Api, 调用 ...

  8. poj3083

    Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8046   Accep ...

  9. Hibernate HQL和原生SQL查询的一点区别

    1.createSQLQuery 1.1默认查询的结果为BigDecimal 1.2通过addScalar("CGD_ID", StandardBasicTypes.LONG)可以 ...

  10. Table 样式设置

    http://www.gzsums.edu.cn/webclass/html/table.html