使用 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 { ...
随机推荐
- [iOS微博项目 - 2.1] - 获得新浪授权接口
A.如何获得新浪的授权接口 登陆新浪的开放平台 注册新浪账号 创建应用 获得应用id和请求地址 查阅相关API 关联需要进行测试的账号 1.登陆开放平台 http://open.weibo.com ...
- pygame简单动态图 & 动态图片的移动
之前在学pygame 时看了一些博客(来自http://eyehere.net/2011/python-pygame-novice-professional-plant-zombie-1/),觉得写得 ...
- [0.1]Plan of kidsearch
To be honest, it's not pretty easy to complete the project. So we have to sort out ideas first. In t ...
- Oracle新建用户、角色,授权,建表空间
oracle数据库的权限系统分为系统权限与对象权限.系统权限( database system privilege )可以让用户执行特定的命令集.例如,create table权限允许用户创建表,gr ...
- 推荐一个CodeProject上的SlideForm控件
CodeProject有一篇文章介绍了怎么实现一个SlideForm,非常不错,收藏在此. http://www.codeproject.com/KB/dialog/csslideform.aspx ...
- TFS代码签入指导
1. 如果文件没有被放入到TFS中, 那么它是不存在的. 这一点是最好被理解的, 如果你的代码没有被签入到代码管理中,那么就不可能被团队的其他人获取的得到. 具体如何将文件纳入到TFS中请参考 Pla ...
- Eclipse10大快捷键组合
一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. Ctrl+Shift+C 快速单行注释 也适用于 ...
- 委派RODC管理员
将某个普通域用户(或组)委派为RODC管理员:
- 根据条件自定义 cxGrid 的单元格样式
当指定的单元格需要指定样式(如字体颜色设置为红色,背景色设置为黄色)时,可按如下步骤进行: 1.添加 csStyleRepository 控件,并新建 Style,设置前景(TextColor).背景 ...
- Codeforces Round #329 (Div. 2) B. Anton and Lines 逆序对
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/pr ...