使用 MJ 自定义下拉刷新
//
// 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 自定义下拉刷新的更多相关文章
- Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)
PullToRefreshScrollView 自定义下拉刷新动画,只需改一处. 以下部分转载自http://blog.csdn.net/superjunjin/article/details/450 ...
- 使用MJRefresh自定义下拉刷新,上拉加载动画
有时候我们需要自己设置下拉刷新,上拉加载动画的实现,这里主要是记录下使用MJRefresh自定义下拉刷新,上拉加载动画..... 下拉刷新我们只需要继承MJRefreshGifHeader即可: 实现 ...
- Android自定义下拉刷新
网上的下拉刷新功能很多,不过基本上都是隐藏header的,而项目里面需要只隐藏部分的header,类似QQ好友动态的效果,修改了一些现有的,最后有很多问题,所以就自己自定义了一个,逻辑也很简单,首先就 ...
- 微信小程序-自定义下拉刷新
最近给别个公司做技术支持,要实现微信小程序上拉刷新与下拉加载更多 微信给出的接口不怎么友好,最终想实现效果类似QQ手机版 ,一共3种下拉刷新状态变化,文字+图片+背景颜色 最终实现后的效果(这里提示有 ...
- 使用 CSS overscroll-behavior 控制滚动行为:自定义下拉刷新和溢出效果
CSS 的新属性 overscroll-behavior 允许开发者覆盖默认的浏览器滚动行为,一般用在滚动到顶部或者底部. 背景 滚动边界和滚动链接(boundary & chaining) ...
- 自定义下拉刷新控件-CBStoreHouseRefreshControl
本文转载至 http://www.cocoachina.com/ios/20141110/10177.html iOS开发自定义刷新CBStoreHouseRefres 介绍 这是一款在Storeho ...
- Android 自定义下拉刷新ListView
package com.dwtedx.qq.view; import android.content.Context; import android.util.AttributeSet; import ...
- 自定义下拉刷新上拉加载View
MainActivity.java package com.heima52.pullrefresh; import java.util.ArrayList; import com.heima52.pu ...
- react-native 自定义 下拉刷新 / 上拉加载更多 组件
1.封装 Scroller 组件 /** * 下拉刷新/上拉加载更多 组件(Scroller) */ import React, {Component} from 'react'; import { ...
随机推荐
- PowerMock简介
PowerMock 写单元测试可能有些难.有时仅仅为了可测试性的目标而不得不牺牲好的设计.通常可测试性和好的测试之间是一致的,但是并不总是如此.比如,由于现存框架的限制,final classes.m ...
- jemalloc优化MySQL、Nginx内存管理
上一篇文章<TCMalloc优化MySQL.Nginx.Redis内存管理>,下面来看下jemalloc jemalloc源于Jason Evans 2006年在BSDcan confer ...
- Hibernate的常用关键类以及接口介绍
上一篇初步的对Hibernate进行了认识,并测试了Hibernate的HelloWorld, 这里主要介绍HibernateTest类中的相关类和接口,以及其作用和特性,关于Session中的相关方 ...
- Java设计模式系列之策略模式
策略模式的定义: 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换,策略模式让算法独立于使用它的客户而独立变化. 策略模式使这些算法在客户端调用它们的时候能够互不影响地变化 ...
- JQuery中的AJAX参数详细介绍
Jquery中AJAX参数详细介绍 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方 ...
- oracle对序列的操作
select t.*, t.rowid from tbl_type t order by t.id desc Select SEQ_TBL_TYPE_ID.NextVal From Dual; ; ; ...
- 自己学会汉化DevExpress控件[转]
1. 文档导读 本文档以颜色区分内容的重要性和不同性,阅读本文档时请注意以下事项: 1. 红色部分表示需要注意的重点内容:(加粗的尤甚) 2. 蓝色部分表示相应于前版本新增的内容: 3. 紫色部分表示 ...
- 剑指OFFER之调整数组顺序使奇数位于偶数前面找(九度OJ1516)
题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 输入: 每个输 ...
- 蓝桥杯--Quadratic Equation
蓝桥杯--Quadratic Equation 问题描述 求解方程ax2+bx+c=0的根.要求a, b, c由用户输入,并且可以为任意实数. 输入格式:输入只有一行,包括三个系数,之间用空格格开. ...
- Hash Table构建
get-item e:\test\* |format-table @{name="aa";expression={$_.name.tostring().split(".& ...