为练手写了一个小的上拉载入很多其它下拉刷新的小的Dome 。

没有太多的技术含量,仅仅是作为新手的启示用。是上一篇下拉载入的扩展。先看一下那个再看这个就easy非常多。

Dome下载:http://download.csdn.net/detail/u010123208/8062715

先来梳理一下:

上拉家在很多其它就是上拉之后在底部现实一个视图,用来提示用户上拉载入很多其它,假设用户上拉就出发事件。进行载入并在试图中给予提示,同一时候后台载入数据,将加入的数据加入数据数组,最后又一次导入列表;

下拉刷新相同的操作,仅仅只是就是将数组清空又一次来导入数据;

首先我们要创建两个view 一个是顶部显示,一个在底部显示 ;

在view中要显示如今文字,一张图片,一个活动指示框(当进行网络请求载入数据的时候显示。其它时候隐藏),假设不太理解下载Dome看一下就知道了。

typedef enum {
InsertStateNomal, //寻常状态
InsertStateDrapUp, //上拉状态
InsertStateDrapDown, //下拉状态
InsertStateRun, //正在载入的状态
}InsertState; @interface HeadView : UIView @property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,assign) InsertState insertState;
@property (nonatomic,strong) UIActivityIndicatorView *activity; - (void)setInsertNomal;
- (void)setInsertDrapDown;
- (void)setInsertRun;
@end @interface FootView : UIView @property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,assign) InsertState insertState;
@property (nonatomic,strong) UIActivityIndicatorView *activity; - (void)setInsertNomal;
- (void)setInsertDrapDoUp;
- (void)setInsertRun; @end

枚举用来指示视图的当前状态;

事实上两个视图的内容什么的都全然一样;

//
// InsertView.m
// RefreshDome
//
// Created by 小屁孩 on 14-10-16.
// Copyright (c) 2014年 XS. All rights reserved.
// #import "InsertView.h" @implementation HeadView @synthesize imageView;
@synthesize label;
@synthesize insertState;
@synthesize activity; - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) { self.backgroundColor = [UIColor orangeColor];
//图片
imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow.png"]];
imageView.frame = CGRectMake(20, frame.size.height-60, 30, 50);
[self addSubview:imageView]; //显示的文字
label = [[UILabel alloc]initWithFrame:CGRectMake(60, frame.size.height-60, 250, 50)];
label.text = @"下拉刷新...";
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label]; //状态
insertState = InsertStateNomal; //活动指示器
activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame = CGRectMake(20,frame.size.height-60, 30, 50);
[self addSubview:activity];
}
return self;
} //初始状态
-(void)setInsertNomal
{
insertState = InsertStateNomal;
label.text = @"下拉刷新.....";
imageView.layer.transform = CATransform3DMakeRotation(M_PI*2, 0, 0, 1);
[activity stopAnimating];
imageView.hidden =NO;
} //下拉状态
- (void)setInsertDrapDown
{
insertState = InsertStateDrapDown;
[UIView beginAnimations:nil context:nil];
label.text = @"释放后刷新.....";
imageView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
[UIView commitAnimations]; } //刷新状态
- (void)setInsertRun
{
insertState =InsertStateRun;
label.text = @"正在刷新.....";
imageView.hidden = YES;
[activity startAnimating];
}
@end @implementation FootView @synthesize imageView;
@synthesize label;
@synthesize insertState;
@synthesize activity; - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) { self.backgroundColor = [UIColor orangeColor];
//图片
imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow.png"]];
imageView.layer.transform = CATransform3DMakeRotation(M_PI , 0, 0, 1);
imageView.frame = CGRectMake(20, 10, 30, 50);
[self addSubview:imageView]; //文字
label = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, 250, 50)];
label.text = @"上拉载入很多其它.....";
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label]; //状态
insertState = InsertStateNomal; //活动指示器
activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activity.frame = CGRectMake(20, 10, 30, 50);
[self addSubview:activity];
}
return self;
} //初始状态
- (void)setInsertNomal
{
insertState = InsertStateNomal;
label.text = @"上拉载入很多其它.....";
imageView.layer.transform = CATransform3DMakeRotation(M_PI , 0, 0, 1);
[activity stopAnimating];
imageView.hidden =NO;
} //上拉状态
- (void)setInsertDrapDoUp
{
insertState = InsertStateDrapUp;
[UIView beginAnimations:nil context:nil];
label.text = @"释放后载入很多其它.....";
imageView.layer.transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
[UIView commitAnimations];
} //载入状态
- (void)setInsertRun
{
insertState = InsertStateRun;
label.text = @"正在载入.....";
imageView.hidden = YES;
[activity startAnimating];
}
@end

最后就是列表了;

事实上在这里面须要注意的:

  • 要如何为表格加入视图
  • 加入的底部视图随着内容的增多,是不断变化的(这里我用了KVO来控制,当数组元素变化后处理位置)
  • 当完毕下拉或者上拉的时候。短暂的视图显示怎么来控制
  • 上拉下拉的推断(UIScrollview代理)条件;

#import <UIKit/UIKit.h>
#import "InsertView.h" @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UITableView *table;
@property (nonatomic,strong) NSMutableArray *tableArray; @end
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
{
HeadView *headView;
FootView *footView;
} @synthesize tableArray;
@synthesize table; - (void)viewDidLoad
{
[super viewDidLoad];
table.frame = CGRectMake(0, 20, 320, [[UIScreen mainScreen]bounds].size.height-20);
table.delegate = self;
table.dataSource = self;
table.tableFooterView = [[UIView alloc]init]; //下拉头部视图
headView = [[HeadView alloc]initWithFrame:CGRectMake(0, -251, DEVICE_FRAME.size.width, 251)];
[table addSubview:headView]; //上拉底部视图
footView = [[FootView alloc]initWithFrame:CGRectMake(0, table.frame.size.height, DEVICE_FRAME.size.width, 251)];
[table addSubview:footView]; //初始化数组
tableArray = [NSMutableArray array];
for (int i = 0; i<15; i++) {
NSURL *url=[NSURL URLWithString:@"http://www.sinaimg.cn/qc/photo_auto/chezhan/2012/50/00/15/80046_950.jpg"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
[tableArray addObject:image];
} float hight =tableArray.count * 60 ;
if (tableArray.count * 60 < [[UIScreen mainScreen]bounds].size.height ) {
hight = table.frame.size.height;
}
footView.frame = CGRectMake(0, hight, 320, 251); [self addObserver:self forKeyPath:@"tableArray" options:NSKeyValueObservingOptionNew context:nil]; } - (void) addtableMutableArray
{
for (int i = 0; i<5; i++) {
NSURL *url=[NSURL URLWithString:@"http://www.sinaimg.cn/qc/photo_auto/chezhan/2012/50/00/15/80046_950.jpg"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
[self.tableArray addObject:image];
}
self.tableArray = tableArray;
[footView setInsertNomal];
[self performSelectorOnMainThread:@selector(endThread) withObject:nil waitUntilDone:NO];
} - (void)endThread
{ [UIView beginAnimations:nil context:nil];
table.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
[UIView commitAnimations];
[table reloadData];
NSLog(@"%d",tableArray.count);
} - (void) refesh
{
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i<15; i++) {
NSURL *url=[NSURL URLWithString:@"http://wenwen.sogou.com/p/20110923/20110923201826-1347223277.jpg"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
[array addObject:image];
}
self.tableArray = array;
[headView setInsertNomal];
[self performSelectorOnMainThread:@selector(endThread) withObject:nil waitUntilDone:NO];
} #pragma mark KVO
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSMutableArray *array = [change objectForKey:@"new"];
float hight =array.count * 60;
if (array.count * 60 < [[UIScreen mainScreen]bounds].size.height ) {
hight = [[UIScreen mainScreen]bounds].size.height;
}
footView.frame = CGRectMake(0, hight, 320, 251); } #pragma mark tabledelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return tableArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identityCell = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identityCell];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identityCell];
}
cell.imageView.image = [tableArray objectAtIndex:indexPath.row];
cell.textLabel.text = @"NibBi";
return cell;
} #pragma mark - scrolldelegae - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (headView.insertState == InsertStateDrapDown) {
[UIView beginAnimations:nil context:nil];
table.contentInset = UIEdgeInsetsMake(70, 0, 0, 0);
[headView setInsertRun];
[UIView commitAnimations];
[self performSelectorInBackground:@selector(refesh) withObject:nil]; }
if (footView.insertState == InsertStateDrapUp) {
[UIView beginAnimations:nil context:nil];
table.contentInset = UIEdgeInsetsMake(0, 0, 70, 0);
[footView setInsertRun];
[UIView commitAnimations];
[self performSelectorInBackground:@selector(addtableMutableArray) withObject:nil];
}
} -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// NSLog(@"%f",scrollView.contentOffset.y);
//上拉载入很多其它转换
if (scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.frame.size.height + 60 && footView.insertState == InsertStateNomal) {
[UIView beginAnimations:nil context:nil];
[footView setInsertDrapDoUp];
[UIView commitAnimations]; }
//下拉刷新转换
if (scrollView.contentOffset.y < -60 && headView.insertState == InsertStateNomal)
{
[UIView beginAnimations:nil context:nil];
[headView setInsertDrapDown];
[UIView commitAnimations];
}
} @end

ios 上拉载入下拉刷新Dome的更多相关文章

  1. ListView装上拉电阻下拉刷新

    主要用到了这个几个文件.MainActivity是界面的Activity,MyAdapter是ListView的自己定义适配,MyListView是自己定义带头部LIistView,假设仅仅须要上拉载 ...

  2. 使用iScroll实现上拉或者下拉刷新

    上拉或者下拉刷新的需求在移动端是非常常见的需求,大部分情况下,实现这个效果都使用网上现有的解决方案,例如有人使用swiper这个插件, 也有人使用iScroll这个滚动插件.本文的示例是利用iscro ...

  3. html5+css3实现上拉和下拉刷新

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  4. 微信小程序实现上拉和下拉加载更多

    在上一篇文章中,我们知道了使用 scroll-view 可以实现上拉加载更多,但是由于 scroll-view 的限制,它无法实现下拉加载更多,这篇文章我们使用 view 组件来实现 上拉和下拉加载更 ...

  5. #Java Web累积#关于MUI的上滑和下拉加载

    其实按照MUI的文档去写,也没什么问题: JSP中: <%@ page contentType="text/html;charset=UTF-8" language=&quo ...

  6. html5+css3实现手机下拉和下拉刷新

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. Arduino 极速入门系列 - 光控灯(2) - 关于开关,上拉、下拉电阻那些事

    接上篇,这次继续讲解光控灯的另外两个组成部分 - 开关和光敏电阻,光控灯里面将会有自锁开关按钮和光敏电阻.这此主要给新玩电子的朋友解释一下开关按钮的做法. 开关按钮的引脚电平读取问题 - 新手专用 我 ...

  8. iOS 点击cell下拉

    iOS  点击cell下拉 代码如下: #import "ViewController.h" @interface ViewController ()<UITableView ...

  9. ios学习--iphone 实现下拉菜单

    原文地址:ios学习--iphone 实现下拉菜单作者:sdglyuan00 #import @interface DropDown1 : UIView <</span>UITabl ...

随机推荐

  1. Python MySQLdb Mac安装遇到的问题

    Mac 下使用Python 连接Mysql 数据库,使用到模块MySQLdb,各种问题都出现,搜集整理下,最后发现最关键的还是Mac 下的Python 版本问题 前置条件: 1. 已经安装mysql ...

  2. zoj 1730 / poj 1455 Crazy Tea Party

    这阵子都没怎么写代码,由于开学,忙于各种琐碎的事情,现在静下来了开始跟着暑假的节奏刷题了. 这道题一开是没看清题目-在寝室刷题就是效率不高... 后来才知道,题目意思是,一个环形序列,1minute可 ...

  3. Java学习笔记九(泛型)

    1.介绍 所谓的泛型就是将类型作为一种參数来传递.有了泛型后类型不再是一成不变的.能够通过泛型參数来指定. 能够提供程序开发的灵活性. 2.泛型类或接口的使用 泛型类声明时.与普通类没有太大的差别,仅 ...

  4. 再淡spring jdbc 连接池断开重连设置

    先看一段错误日志: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConne ...

  5. Swift - 手机摇晃的监测和响应

    摇晃手机也是一种常用的交互手段(比如微信摇一摇功能).iOS SDK中已经将shake事件方便地融合进去了,就像触发touch事件一样简单,发生摇晃事件后程序会自动执行. 1 2 3 4 5 6 7 ...

  6. HDU 2045 不easy系列之(3)—— LELE的RPG难题

    思路: 1.若前n-1位涂的颜色是符合条件的,则因为首尾不同,再加入一位时,仅仅有1种方法:即s[n] = s[n-1] 2.若前n-1位组成的串不符合,再加入一位后合法.即由于首尾同样而引起的不合法 ...

  7. C#超级有用的一种类型—匿名类型

    顾名思义 匿名类型就是没有名字的类型.当一个新的匿名对象定义与前面已经存在的类型定义的内部变量类型同样时,编译器就会仅仅生成一个类定义,而不是各一个. 匿名类型对象中仍然能够再包括匿名对象. 在C#3 ...

  8. Qt 打包发布 不能动态打开图片显示问题

    刚写完一个图片标注工具, 发现在我电脑可以实时打开照片显示出来,在他人的电脑上就不可以. 原来Qt默认只识别png 具体解决方案: 原地址:http://blog.csdn.net/goodlixue ...

  9. 基于visual Studio2013解决C语言竞赛题之1055排序

       题目 解决代码及点评 /* 功能:已知A是有30个元素的整型数组,编写一个对A[I1]到A[I2](I1≤I2)之间的元素排序的函数(从大到小排序) 请调用上述函数先将A[5]至A[ ...

  10. Python写入文件,但是发现文件为空,竟然未写入!

    问题描述: fw=open(r'C:\test.txt','w') s="Hello World!" fw.write(s) ========== 此时查看C盘根目录,发现test ...