日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/20 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

版權聲明:本文博主原創文章。博客,未經同意不得轉載。

總結

以上是生活随笔為你收集整理的ios-上拉电阻负载许多其他接口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。