For practicing handwriting a small pull-up loads more drop-down refreshes for small dome.
Not a lot of technical content, just as a beginner's inspiration. is an extension of the previous drop-down load. It's much easier to look at it first.
Dome Download: http://download.csdn.net/detail/u010123208/8062715
First to Comb:
Pull home in more is pull up after the bottom of the reality of a view, used to prompt the user to pull the load more, if the user pull up on the departure event, load and in the attempt to give hints, while the background load data, add the data into the data array, and finally re-import the list;
The drop-down refreshes the same thing simply by emptying the array and re-importing the data;
First we want to create two view one is the top display, one at the bottom of the display;
In view to display the current text, a picture, an Activity indicator box (when the network request to load data display, other time hidden), if you do not understand the download dome to see it.
typedef enum { insertstatenomal, //normal state Insertstatedrapup, //Pull status insertstatedrapdown,//drop-down status Insertstaterun, //loading state}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
Enumeration is used to indicate the current state of the view;
In fact, the contents of the two views are exactly the same;
insertview.m//refreshdome////Created by little punk 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]; Picture ImageView = [[Uiimageview alloc]initwithimage:[uiimage imagenamed:@ "Arrow.png"]]; Imageview.frame = CGRectMake (frame.size.height-60, 30, 50); [Self addsubview:imageview]; The text displayed is label = [[UILabel alloc]initwithframe:cgrectmake (250, FRAME.SIZE.HEIGHT-60, 50)]; Label.text = @ "drop-down refresh ..."; Label.textalignment = Nstextalignmentcenter; [Self Addsubview:label]; state insertstate = Insertstatenomal; Active indicator activity = [[Uiactivityindicatorview alloc]initwithactivityindicatorstyle:Uiactivityindicatorviewstylegray]; Activity.frame = CGRectMake (20,frame.size.height-60, 30, 50); [Self addsubview:activity]; } return self;} Initial state-(void) setinsertnomal{insertstate = Insertstatenomal; Label.text = @ "drop-down refresh ..."; ImageView.layer.transform = catransform3dmakerotation (m_pi*2, 0, 0, 1); [Activity stopanimating]; Imageview.hidden =no;} Drop-down state-(void) setinsertdrapdown{insertstate = Insertstatedrapdown; [UIView Beginanimations:nil Context:nil]; Label.text = @ "Refresh after release ..."; ImageView.layer.transform = catransform3dmakerotation (m_pi, 0, 0, 1); [UIView commitanimations]; }//Refresh Status-(void) setinsertrun{insertstate =insertstaterun; Label.text = @ "refreshing ..."; 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]; Picture 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]; Text label = [[UILabel alloc]initwithframe:cgrectmake (60, 10, 250, 50)]; Label.text = @ "Pull up loads more ..."; Label.textalignment = Nstextalignmentcenter; [Self Addsubview:label]; state insertstate = Insertstatenomal; Active indicator activity = [[Uiactivityindicatorview Alloc]initwithactivityindicatorstyle:uiactivityindicatorviewstylegray ]; Activity.frame = CGRectMake (20, 10, 30, 50); [Self addsubview:activity]; } return self;} Initial state-(void) setinsertnomal{insertstate = Insertstatenomal; Label.text = @ "Pull up loads more ..."; ImageView.layer.transform = catransform3dmakerotation (m_pi, 0,0, 1); [Activity stopanimating]; Imageview.hidden =no;} Pull-up state-(void) setinsertdrapdoup{insertstate = Insertstatedrapup; [UIView Beginanimations:nil Context:nil]; Label.text = @ "Load more after release ..."; ImageView.layer.transform = Catransform3dmakerotation (M_PI * 2, 0, 0, 1); [UIView commitanimations];} Load state-(void) setinsertrun{insertstate = Insertstaterun; Label.text = @ "Loading ..."; Imageview.hidden = YES; [Activity startanimating];} @end
The last is the list;
In fact, in this area need to pay attention to:
- How do I add a view to a table
- The bottom view added is constantly changing as the content grows (here I use the KVO to control when the array element changes after the position is processed)
- When the pull-down or pull-up is complete, a short view shows how to control
- Pull down the judgment (Uiscrollview agent) condition;
#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, +, [UIScreen mainscreen]bounds].size.height-20); Table.delegate = self; Table.datasource = self; Table.tablefooterview = [[UIView alloc]init]; Drop-down head view Headview = [[Headview alloc]initwithframe:cgrectmake (0, -251, DEVICE_FRAME.size.width, 251)]; [Table Addsubview:headview]; Pull-up bottom view Footview = [[Footview alloc]initwithframe:cgrectmake (0, Table.frame.size.height, DEVICE_FRAME.size.width, 251)]; [Table Addsubview:footview]; Initializes an array of 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 * < [[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.sina Img.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 * < [[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:identit Ycell]; } 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); Pull-up load more conversions if (Scrollview.contentoffset.y > Scrollview.contentsize.height-scrollview.frame.size.height + && Amp Footview.insertstate = = insertstatenomal) {[UIView beginanimations:nil context:nil]; [Footview Setinsertdrapdoup]; [UIView commitanimations]; }//drop-down refresh conversion if (Scrollview.contentoffset.y < -60 && Headview.insertstate = = insertstatenomal) { [UIVIew Beginanimations:nil Context:nil]; [Headview Setinsertdrapdown]; [UIView commitanimations]; }} @end
iOS pull-up load drop-down refresh Dome