ios-上拉电阻负载许多其他接口

简介:

想尝试拉加载意识到有多少开始了他的研究之旅,我看了两天做出最终的界面。

之所以这么慢是由于,我不知道要将上拉出现的view放在哪。就能在scrollView拉究竟部的时候被拉出来。还有就是怎么拉出来之后停在这里。网上下载样例之后研究了两天:



先说一下,在以下处理图片中橘色view的位置的时候用了kvo进行了监听。


先一个枚举 来指示眼下刷新view是在哪个状态:

typedef enum {
    RefreshStateLoading = 1,//刷新状态为正在载入
    RefreshStateRelease,    //下拉完毕释放之前
    RefreshStateNomal,      //原始状态
}RefreshState;


以下一个类view来描写叙述刷新view


@interface FootView : UIView

@property (nonatomic,strong) UIActivityIndicatorView *activity;//活动指示条
@property (nonatomic,strong) UIImageView *imageView;            //箭头图片
@property (nonatomic,strong) UILabel *infolabel;                //文字指示
@property (nonatomic,assign) RefreshState refreshState;         //刷新的状态

- (void)refreshStateLoading;
- (void)refreshStateNomal;
- (void)refreshStateRelsease;

@end

#import "FootView.h"

@implementation FootView

@synthesize activity;
@synthesize imageView;
@synthesize infolabel;
@synthesize refreshState;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        
        //活动指示器初始化
        activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        activity.frame = CGRectMake(10, 0, 50, 70);
        [self addSubview:activity];
        
        //箭头图片初始化
        imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 50)];
        imageView.image = [UIImage imageNamed:@"blackArrow.png"];
        [self addSubview:imageView];
        
        //信息label初始化
        infolabel = [[UILabel alloc]initWithFrame:CGRectMake(100,0 ,100, 70)];
        infolabel.text = @"下拉刷新...";
        infolabel.font = [UIFont fontWithName:@"Helvetica" size:20];
        infolabel.textAlignment = NSTextAlignmentCenter;
        infolabel.textColor = [UIColor blackColor];
        [self addSubview:infolabel];
        
        //设置初始状态
        self.refreshState = RefreshStateNomal;
    }
    return self;
}

//初始状态
- (void)refreshStateNomal
{
    self.refreshState = RefreshStateNomal;
    [self.activity stopAnimating];
    self.infolabel.text = @"下拉载入很多其它...";
    self.imageView.layer.transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
    self.imageView.hidden = NO;
}

//正在请求数据时
- (void)refreshStateLoading
{
    self.refreshState = RefreshStateLoading;
    self.imageView.hidden = YES;
    [UIView beginAnimations:nil context:nil];
    self.infolabel.text = @"正在载入...";
    [self.activity startAnimating];
    [UIView commitAnimations];
}

//下拉完毕后
- (void)refreshStateRelsease
{
    self.refreshState = RefreshStateRelease;
    [UIView beginAnimations:nil context:nil];
    self.infolabel.text = @"释放后载入...";
    self.imageView.layer.transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
    [UIView commitAnimations];
    
}



@end

以下来写table

#import <UIKit/UIKit.h>

@interface MyTableVC : UITableViewController<UIScrollViewDelegate>

@property (nonatomic,strong) NSMutableArray *dataArray;//数据


@end

#import "MyTableVC.h"
#import "FootView.h"

#define TABLE_CELL_HIGHT 50.0

@interface MyTableVC ()

@end

@implementation MyTableVC
{
    FootView *footView;
}

@synthesize dataArray;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    dataArray = [NSMutableArray arrayWithArray:@[@"列表1",@"列表2",@"列表3",@"列表2",@"列表3",@"列表2",@"列表3",@"列表2",@"列表3",@"列表2",@"列表3",@"列表2",@"列表3",@"列表2",@"列表5"]];
    [self addPullToRefreshFooter];
}

//加入FootView指示器
- (void)addPullToRefreshFooter
{
    //FootView初始化
    footView = [[FootView alloc]initWithFrame:CGRectMake(0, dataArray.count*50 , 320, 251)];
    [self.tableView addSubview:footView];
    //监视数据数组
    [self addObserver:self forKeyPath:@"dataArray" options:NSKeyValueObservingOptionNew context:nil];
}




#pragma mark - Table view data source

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return TABLE_CELL_HIGHT;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *inditifierCell = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:inditifierCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:inditifierCell];
    }
    cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray *new = [[NSMutableArray alloc]initWithArray:dataArray];
    [new addObject:@"张三"];
    self.dataArray  = new;
    [footView refreshStateNomal];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
}

#pragma mark - kvo
//用于监听dataArray数组来设置footview的位置
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"%d",dataArray.count);
    NSMutableArray *mutableArray = [change objectForKey:@"new"];
    footView.frame = CGRectMake(0,TABLE_CELL_HIGHT* mutableArray.count, 320, 251);
    [self.tableView reloadData];
}

#pragma mark - Scroller

//当scroller滑动时调用
- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (footView.refreshState == RefreshStateNomal&& scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.frame.size.height + 70) {
        [footView refreshStateRelsease];
    }
}

//当滑动结束时调用
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (footView.refreshState == RefreshStateRelease) {
        [UIView beginAnimations:nil context:nil];
        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 70, 0);
        [footView refreshStateLoading];
        [UIView commitAnimations];
    }
}

@end


在table中处理一些事件:

为了測试加入数据后footview的位置是否会跟着变动。当点击cell的时候会加入一个数据。

为了測试载入完毕后第二次拖拽是否页面还可以完毕,当点击cell的时候foottview会停止;


下载代码:http://download.csdn.net/detail/u010123208/8036577

版权声明:本文博主原创文章。博客,未经同意不得转载。








本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4890967.html,如需转载请自行联系原作者


相关文章
|
5月前
|
iOS开发
Airtest的iOS实用接口介绍
Airtest的iOS实用接口介绍
|
iOS开发
关于使用iOS的弹窗接口出现“WDARequestError”报错的问题说明
关于使用iOS的弹窗接口出现“WDARequestError”报错的问题说明
377 0
|
监控 IDE 开发工具
1.1.8版本Airtest新增的iOS接口究竟有多香?!今天告诉你
1.1.8版本Airtest新增的iOS接口究竟有多香?!今天告诉你
393 0
|
JSON API 数据格式
iOS保存接口返回枚举数据为本地json文件可用于测试
iOS保存接口返回枚举数据为本地json文件可用于测试
337 0
iOS保存接口返回枚举数据为本地json文件可用于测试
|
iOS开发 开发者 UED
iOS 前后台切换的接口函数
iOS 前后台切换的接口函数
165 0
iOS 前后台切换的接口函数
|
算法 Java 数据库
java结合android和ios的三端非对称接口加密讲解
  算法:有rsa及aes算法   Java端处理方式:   入参处理方式   1、参数通过request.getParameter获取的话,可以通过自己定义一个filter来进行处理。   定义两个类,分别继承HttpServletRequestWrapper及Filter,将该filter配置到web.xml里面,在其他filter前面,以免影响程序获取参数的调用   public class SafeTextRequestWrapper extends HttpServletRequestWrapper {   public SafeTextRequestWrapper(H
319 0
|
iOS开发
iOS锁屏代码注意使用新接口
iOS锁屏代码注意使用新接口
150 0
|
开发工具 iOS开发
产品百科 | RTC iOS SDK 播放音效文件的接口方法
阿里云 RTC SDK 为您提供伴奏文件和音效文件的相关接口方法,您可以通过本文了解其具体的实现方法。
产品百科 | RTC iOS SDK 播放音效文件的接口方法
在使用蓝牙接口,遇到IOS下正常,Android下不正常的简易处理方法
如果遇到以上的情况怎么办,先确定下在调试的时候是否打开了调试面板, 如果有打开请关闭调试面板看是否还有问题,目前在安卓上打开调试面板是会有影响到蓝牙接口的使用,从之前遇到过这些问题的统计中也确实是因为这个原因
446 0