UITableView之上拉刷新
来源:互联网 发布:绵阳广播电视网络 编辑:程序博客网 时间:2024/06/11 23:45
分析 表视图上拉刷新的思路1.当上拉刷新的时候,底部那个显示刷新样式的是什么东西?<1.会不会是tableFooterView ?不会,因为tableFooterView是表视图的内容。 如果用tableFooterView的话,我们怎么完成反弹加载数据的效果?<2.封装视图?必须要自己封装一个视图,并且因为刷新视图有图有label,用button就好2.怎么封装呢?刷新一共三步<1.上拉加载更多<2.在某一程度上是 松开加载更多<3.读取中…什么时候显示上拉加载更多呢?这个视图怎么封装?0.建立容器视图1.我们首先将视图放在表视图最底2.当表视图的偏移量到了一定范围我们将视图显示为上拉加载更多3.超过一定范围,则显示为松开加载更多,结束拖拽,则加载4.此时显示读取中 ,刷新数据<pre name="code" class="objc">#import "YXFreshFooterView.h"@interface YXFreshFooterView ()@property (nonatomic,weak) UIButton *alertButton;@property (nonatomic,weak) UIView *activityView;@end@implementation YXFreshFooterView+ (id)freshFooterView { return [[self alloc] init];}// 设置刷新视图的frame 根据tableView来设置- (void)willMoveToSuperview:(UIView *)newSuperview { UITableView *tableView = (UITableView *)newSuperview; self.y = tableView.contentSize.height; self.width = tableView.width; self.height = 60; self.backgroundColor = [UIColor lightGrayColor];}/** * 底部刷新视图的状态 */- (void)setFreshFooterViewStatus:(FreshFooterViewStatus)freshFooterViewStatus { _freshFooterViewStatus = freshFooterViewStatus; switch (freshFooterViewStatus) { // 更换状态时,设置标题和旋转 case FreshFooterViewStatusDragging: [self.alertButton setTitle:@"拖拽加载更多" forState:UIControlStateNormal]; self.alertButton.imageView.transform = CGAffineTransformMakeRotation(M_PI); break; case FreshFooterViewStatusEndDragging: { [self.alertButton setTitle:@"松开读取更多" forState:UIControlStateNormal]; [UIView animateWithDuration:0.3 animations:^{ // 使图形的形变恢复到最开始的状态 self.alertButton.imageView.transform = CGAffineTransformIdentity; }]; } break; case FreshFooterViewStatusLoading: self.alertButton.hidden = YES; [self activityView]; break; default: break; }}#pragma mark - 懒加载- (UIButton *)alertButton { if (_alertButton == nil) { UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self addSubview:alertButton]; // 保存全局变量 _alertButton = alertButton; alertButton.frame = self.bounds; // 设置图片 [alertButton setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal]; // 关闭用户交互 alertButton.userInteractionEnabled = NO; alertButton.titleLabel.font = [UIFont systemFontOfSize:13]; // 调节上下左右边距 - > 设置小图标与文字的距离 alertButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 60); // 这是系统提供的宏定义,专门用来表示π 的关系 alertButton.imageView.transform = CGAffineTransformMakeRotation(M_PI); // 使用形变属性,让image图标旋转180度 // UIButton 为什么可以显示文字? UILabel // UIButton 为什么可以显示图片? UIImageView // UIButton 为什么能够响应用户的点击事件呢? UIControl addTarget... // UIButton 它的设计原则是什么呢? // 如何更好的管理这些复杂的子控件之间的关系呢? // 尽量以整体作为管理的思想进行设计,然后对外流出多种管理接口,可以整体管理的接口(属性),可以单独管理的接口(属性) } return _alertButton;}- (UIView *)activityView { if (_activityView == nil) { // 容器视图 UIView *tmpView = [[UIView alloc] init]; // 菊花 + label [self addSubview:tmpView]; _activityView = tmpView; tmpView.frame = self.bounds; UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] init]; // 加上菊花 [tmpView addSubview:activityIndicatorView]; activityIndicatorView.x = 20; activityIndicatorView.y = 30; // 改变指示器的风格 activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; // 启动菊花动画 [activityIndicatorView startAnimating]; // 加上label UILabel *titleLabel = [[UILabel alloc] init]; [tmpView addSubview:titleLabel]; titleLabel.text = @"读取中..."; titleLabel.frame = CGRectMake(60, 10, 100, 30); } return _activityView;}@end
#import "YXFreshFooterView.h"@interface YXFreshFooterView ()@property (nonatomic,weak) UIButton *alertButton;@property (nonatomic,weak) UIView *activityView;@end@implementation YXFreshFooterView+ (id)freshFooterView { return [[self alloc] init];}// 设置刷新视图的frame 根据tableView来设置- (void)willMoveToSuperview:(UIView *)newSuperview { UITableView *tableView = (UITableView *)newSuperview; self.y = tableView.contentSize.height; self.width = tableView.width; self.height = 60; self.backgroundColor = [UIColor lightGrayColor];}/** * 底部刷新视图的状态 */- (void)setFreshFooterViewStatus:(FreshFooterViewStatus)freshFooterViewStatus { _freshFooterViewStatus = freshFooterViewStatus; switch (freshFooterViewStatus) { // 更换状态时,设置标题和旋转 case FreshFooterViewStatusDragging: [self.alertButton setTitle:@"拖拽加载更多" forState:UIControlStateNormal]; self.alertButton.imageView.transform = CGAffineTransformMakeRotation(M_PI); break; case FreshFooterViewStatusEndDragging: { [self.alertButton setTitle:@"松开读取更多" forState:UIControlStateNormal]; [UIView animateWithDuration:0.3 animations:^{ // 使图形的形变恢复到最开始的状态 self.alertButton.imageView.transform = CGAffineTransformIdentity; }]; } break; case FreshFooterViewStatusLoading: self.alertButton.hidden = YES; [self activityView]; break; default: break; }}#pragma mark - 懒加载- (UIButton *)alertButton { if (_alertButton == nil) { UIButton *alertButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self addSubview:alertButton]; // 保存全局变量 _alertButton = alertButton; alertButton.frame = self.bounds; // 设置图片 [alertButton setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal]; // 关闭用户交互 alertButton.userInteractionEnabled = NO; alertButton.titleLabel.font = [UIFont systemFontOfSize:13]; // 调节上下左右边距 - > 设置小图标与文字的距离 alertButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 60); // 这是系统提供的宏定义,专门用来表示π 的关系 // 使用形变属性,让image图标旋转180度 // UIButton 为什么可以显示文字? UILabel // UIButton 为什么可以显示图片? UIImageView // UIButton 为什么能够响应用户的点击事件呢? UIControl addTarget... // UIButton 它的设计原则是什么呢? // 如何更好的管理这些复杂的子控件之间的关系呢? // 尽量以整体作为管理的思想进行设计,然后对外流出多种管理接口,可以整体管理的接口(属性),可以单独管理的接口(属性) } return _alertButton;}- (UIView *)activityView { if (_activityView == nil) { // 容器视图 UIView *tmpView = [[UIView alloc] init]; // 菊花 + label [self addSubview:tmpView]; _activityView = tmpView; tmpView.frame = self.bounds; UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] init]; // 加上菊花 [tmpView addSubview:activityIndicatorView]; activityIndicatorView.x = 20; activityIndicatorView.y = 30; // 改变指示器的风格 activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; // 启动菊花动画 [activityIndicatorView startAnimating]; // 加上label UILabel *titleLabel = [[UILabel alloc] init]; [tmpView addSubview:titleLabel]; titleLabel.text = @"读取中..."; titleLabel.frame = CGRectMake(60, 10, 100, 30); } return _activityView;}@end
0 0
- UITableView之上拉刷新
- 自定义RecyclerView之上拉刷新更新数据
- UITableView上拉下拉刷新
- UITableView之下拉刷新上拉加载
- UITableView 上拉刷新,下拉刷新
- iOS开发之上拉刷新(加载更多)(EGORefreshTableFooterView)
- 自定义控件之上拉刷新下拉加载RefreshListView
- 微信小程序之上拉加载和下拉刷新
- react-native之上拉加载,下拉刷新组件封装
- UIScrollView UITableView 上拉刷新源码
- UITableView上拉与下拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView底部FooterView实现上拉刷新
- UItableView的上拉与下拉刷新
- UITableView底部FooterView实现上拉刷新
- UITableView:下拉刷新和上拉加载
- iOS UITableView系统自带下拉刷新
- 实时获取浏览器的地址栏的网页地址
- POJ 1183 反正切函数的应用
- js的2种继承方式详解
- 树莓派2model B 通过蓝牙实现A2DP协议连接手机播放音乐
- cocos2dx 记录
- UITableView之上拉刷新
- 小心别让圆角成了你列表的帧数杀手 --关于设置圆角导致卡顿的深层原因解析
- DOS命令初接触
- POJ 3687 Labeling Balls (反向拓扑排序)
- 剑指offer_面试题26_复杂链表的复制
- 使用C++ 11 实现阻塞队列
- windows 消息机制的概述
- (一二三)基于GCD的dispatch_once实现单例设计
- 百股经项目部分知识点