使用 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 { ...
随机推荐
- Java每日一则-001
Java中类名与文件名的关系 1.Java保存的文件名必须与类名一致: 2.如果文件中只有一个类,文件名必须与类名一致: 3.一个Java文件中只能有一个public类: 4.如果文件中不止一个类,文 ...
- Nuttx操作系统
前几天答辩的时候看到有同学在用,回来后查了点资料. 来源:天又亮了 1 NuttX 实时操作系统 NuttX 是一个实时操作系统(RTOS),强调标准兼容和小型封装,具有从8位到32位微控制器环境的 ...
- Namespaces(命名空间)
datastore,Blobstore,memcache一起为应用存储数据.这对于在全球范围内分割数据是有用的.比如,一个应用可以为多个公司服务,每个公司可以看到它自己的隔离的应用实例,没有公司可以看 ...
- emacs资源
当clone github时若连接不上,可以使用http代理,形如:export http_proxy=61.172.249.94:80一年成为emacs高手: https://github ...
- 第二百五十九天 how can I 坚持
晚上,弟弟给我说了下他前几天发生的事,这孩子,有事就不知道说下,自己闷在心里. 刘松打算最近买房了,弟弟和建哥也考虑买,让他俩商量着来吧,早晚都得买. 有点揪心.想结婚不知道该和谁结... 睡觉.烦.
- 虚拟攻防系统 HoneyPot
转载原地址 http://www.2cto.com/Article/200410/9.html Honeypot 是一个故意设计为有缺陷的系统,通常是用来对入侵者的行为进行警报或者 诱骗.传统的 Ho ...
- POJ 3169 Layout (spfa+差分约束)
题目链接:http://poj.org/problem?id=3169 差分约束的解释:http://www.cnblogs.com/void/archive/2011/08/26/2153928.h ...
- 破解NET的四大神器
原本这篇文章可以更早一星期写出来与大家分享,由于某方面的原因耽搁到现在,心里竟有那么一点好像对不住大家的感觉.这当然与神器有关,因为我发现利用这四大神器我似乎觉得几乎所有的NET程序破解都不在话下了 ...
- DynamoDB Local for Desktop Development
Would you like to be able to write and test code that uses the Amazon DynamoDB API even if you have ...
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水题
A. Lineland MailTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/probl ...