Refresh Dome and iosdome from the pull and load drop-down lists on ios

Source: Internet
Author: User

Refresh Dome and iosdome from the pull and load drop-down lists on ios

A small pull-up load of more pull-down and refresh small Dome is written for the trainer.

There is not much technical content, but it is just used as an inspiration for new users. Is the extension of the last drop-down load. It is much easier to look at it first.


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


Let's take a look:

The pull-up home is a view on the bottom after the pull-up, which is used to prompt the user to pull up and load more. If the user pulls up, the event is triggered, load and give a prompt in the attempt. At the same time, load the data in the background, add the added data to the data array, and then re-import the list;

The same operation is to clear the array and re-import the data;

First, we need to create two views. One is the top display and the other is the bottom display;

Display the current text, an image, and an activity indicator box in the view (hidden when network requests load data ), if you do not understand how to download the Dome file, you can see it.

Typedef enum {InsertStateNomal, // InsertStateDrapUp, // InsertStateDrapUp, // InsertStateDrapDown, // InsertStateRun, // loading status} InsertState; @ interface HeadView: UIView @ property (nonatomic, strong) UIImageView * imageView; @ property (nonatomic, strong) UILabel * label; @ property (nonatomic, assign) InsertState insertState; @ property (nonatomic, strong) optional * 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 status of the view;


In fact, the content of both views is exactly the same;

//// InsertView. m // RefreshDome /// Created by kiddie 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]; // image imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "arrow.png"]; imageView. frame = CGRectMake (20, frame. size. height-60, 30, 50); [self addSubview: imageView]; // The displayed text label = [[UILabel alloc] initWithFrame: CGRectMake (60, frame. size. height-60, 250, 50)]; label. text = @ "pull-down refresh... "; label. textAlignment = NSTextAlignmentCenter; [self addSubview: label]; // status insertState = InsertStateNomal; // activity indicator activity = [[UIActivityIndicatorView alloc] activities: activities]; activity. frame = CGRectMake (20, frame. size. height-60, 30, 50); [self addSubview: activity];} return self;} // initial state-(void) setInsertNomal {insertState = InsertStateNomal; label. text = @ "pull-down refresh ..... "; imageView. layer. transform = CATransform3DMakeRotation (M_PI * 2, 0, 0, 1); [activity stopAnimating]; imageView. hidden = NO;} // The drop-down status-(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]; // image 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 to load more ..... "; label. textAlignment = NSTextAlignmentCenter; [self addSubview: label]; // status insertState = InsertStateNomal; // activity indicator activity = [[UIActivityIndicatorView alloc] activities: activities]; activity. frame = CGRectMake (20, 10, 30, 50); [self addSubview: activity];} return self ;}// initial state-(void) setInsertNomal {insertState = InsertStateNomal; label. text = @ "pull up to load more ..... "; imageView. layer. transform = CATransform3DMakeRotation (M_PI, 0, 0, 1); [activity stopAnimating]; imageView. hidden = NO;} // pull up status-(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];} // loading status-(void) setInsertRun {insertState = InsertStateRun; label. text = @ "loading ..... "; imageView. hidden = YES; [activity startAnimating];} @ end


Finally, the list is displayed;


Note the following:

  • How to add a view to a table
  • The added bottom view is constantly changing as the content increases (here I use KVO to control the position after the array element changes)
  • How to control the short view display when the pull-down or pull-up is complete
  • UIScrollview proxy 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, 20,320, [[UIScreen mainScreen] bounds]. size. height-20); table. delegate = self; table. dataSource = self; table. tableFooterView = [[UIView alloc] init]; // The headView of the drop-down header = [[HeadView alloc] initWithFrame: CGRectMake (0,-251, DEVICE_FRAME.size.width, 251)]; [table addSubview: headView]; // top and bottom views footView = [[FootView alloc] initWithFrame: CGRectMake (0, table. frame. size. height, DEVICE_FRAME.size.width, 251)]; [table addSubview: footView]; // initialize the array 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 succeeded]; [self generated mselecw.mainthread: @ 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 defined mselec1_mainthread: @ selector (endThread) withObject: nil waitUntilDone: NO] ;}# pragma mark KVO-(void) Principal :( 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 progress :( NSIndexPath *) indexPath {return 60;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * identityCell = @ "Cell"; UITableViewCell * cell = [tableView metadata: 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 = values (70, 0, 0, 0); [headView setInsertRun]; [UIView commitAnimations]; [self defined mselectorinbackground: @ selector (refesh) withObject: nil];} if (footView. insertState = InsertStateDrapUp) {[UIView beginAnimations: nil context: nil]; table. contentInset = inputs (0, 0, 70, 0); [footView setInsertRun]; [UIView commitAnimations]; [self defined mselectorinbackground: @ selector (inputs) withObject: nil];} -(void) scrollViewDidScroll :( UIScrollView *) scrollView {// NSLog (@ "% f", scrollView. contentOffset. y); // pull up to load more conversions if (scrollView. contentOffset. y> scrollView. contentSize. height-scrollView. frame. size. height + 60 & footView. insertState = InsertStateNomal) {[UIView beginAnimations: nil context: nil]; [footView setInsertDrapDoUp]; [UIView commitAnimations];} // pull-down refresh and convert if. contentOffset. y <-60 & headView. insertState = InsertStateNomal) {[UIView beginAnimations: nil context: nil]; [headView setInsertDrapDown]; [UIView commitAnimations];} @ end




How to add a network switch in the iPhone 5C (ios7) drop-down menu, like android

Is it about switching the cellular mobile network?
You cannot add it yourself without jailbreak. Check if the custom control center can be updated after Apple.
All settings for the pull-up and drop-down menus are in the notification center and control center.
Hope to help you

Can I use the pull-up and drop-down menus on the screen lock page of The ios71 system? If there is any information, do not view the black screen and then press the information to slide and unlock

Of course ~
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.