tableView 头部添加状态 今日头条刷新数据效果
2017-05-26 10:51
786 查看
有的APP如今日头条 在刷新了之后在列表头会出现一条 已经刷新n条数据的提示,,或者是断开网络连接的提示,,出现和消失提示的时候列表会跟着移动,,这里写了个类似的实现,,原理是给tableview 添加头视图,,实现很简单,,如果你的列表有头视图做轮播图,,想用这个方法,,建议把轮播放进cell里实现。。如果不想用cell实现轮播图的话。。那就不用往下看啦。。。。
![](http://img.blog.csdn.net/20170526104642569?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmxnMTU1NDExMjQ1MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
创建一对HeadTipTool 文件,,继承于NSObject
HeadTipTool.h 文件中 写一个接口
#import <UIKit/UIKit.h>
@interface HeadTip : NSObject
/// tableview 要添加提示的列表tableview
/// tishi 自定义要提示的文字内容
/// time 提示条停留的时间
/// height 提示条的高度
/// textColor 提示文字的颜色
/// backgroundColor 提示框背景颜色
/// font 提示文字的大小
+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font;
@end
HeadTipTool.m 文件中 实现接口方法
- (instancetype)init{
self = [super
init];
if (self) {
}
return
self;
}
+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font{
UILabel *headLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0)];
[UIView
animateWithDuration:0.5
animations:^{
headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
height);
tableView.tableHeaderView = headLabel;
}];
headLabel.textColor = textColor;
headLabel.backgroundColor = backgroundColor;
headLabel.font = font;
headLabel.textAlignment =
NSTextAlignmentCenter;
headLabel.text = tishi;
dispatch_time_t delayTime =
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time/*延迟执行时间*/
* NSEC_PER_SEC));
dispatch_after(delayTime,
dispatch_get_main_queue(), ^{
[UIView
animateWithDuration:0.5
animations:^{
headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0);
tableView.tableHeaderView = headLabel;
}completion:^(BOOL finished) {
tableView.tableHeaderView =
nil;
}];
});
}
调用方法,, 可以用于下拉刷新 结束刷新的时候调用,,也可以在断网的时候调用提示。。
需要使用的controller
#import "HeadTipTool.h"
[HeadTip
addHeadTipWithTableView:self.listTableView
withTishi:@"请检查网络连接"
withTime:2
tishiHeight:30
textColor:[UIColor
blueColor]
backgroundColor:[UIColor
yellowColor]
font:[UIFont
systemFontOfSize:12]];
创建一对HeadTipTool 文件,,继承于NSObject
HeadTipTool.h 文件中 写一个接口
#import <UIKit/UIKit.h>
@interface HeadTip : NSObject
/// tableview 要添加提示的列表tableview
/// tishi 自定义要提示的文字内容
/// time 提示条停留的时间
/// height 提示条的高度
/// textColor 提示文字的颜色
/// backgroundColor 提示框背景颜色
/// font 提示文字的大小
+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font;
@end
HeadTipTool.m 文件中 实现接口方法
- (instancetype)init{
self = [super
init];
if (self) {
}
return
self;
}
+ (void)addHeadTipWithTableView:(UITableView *)tableView withTishi:(NSString
*)tishi withTime:(NSInteger)time tishiHeight:(CGFloat)height textColor:(UIColor *)textColor
backgroundColor:(UIColor *)backgroundColor font:(UIFont *)font{
UILabel *headLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0)];
[UIView
animateWithDuration:0.5
animations:^{
headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
height);
tableView.tableHeaderView = headLabel;
}];
headLabel.textColor = textColor;
headLabel.backgroundColor = backgroundColor;
headLabel.font = font;
headLabel.textAlignment =
NSTextAlignmentCenter;
headLabel.text = tishi;
dispatch_time_t delayTime =
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time/*延迟执行时间*/
* NSEC_PER_SEC));
dispatch_after(delayTime,
dispatch_get_main_queue(), ^{
[UIView
animateWithDuration:0.5
animations:^{
headLabel.frame =
CGRectMake(0,
0, [UIScreen
mainScreen].bounds.size.width,
0);
tableView.tableHeaderView = headLabel;
}completion:^(BOOL finished) {
tableView.tableHeaderView =
nil;
}];
});
}
调用方法,, 可以用于下拉刷新 结束刷新的时候调用,,也可以在断网的时候调用提示。。
需要使用的controller
#import "HeadTipTool.h"
[HeadTip
addHeadTipWithTableView:self.listTableView
withTishi:@"请检查网络连接"
withTime:2
tishiHeight:30
textColor:[UIColor
blueColor]
backgroundColor:[UIColor
yellowColor]
font:[UIFont
systemFontOfSize:12]];
相关文章推荐
- 仿今日头条下拉出现SearchBar,再下拉刷新效果,SearchListView实现以及原理讲解
- 【Android】仿今日头条简单的刷新效果
- 仿今日头条下拉出现SearchBar,再下拉刷新效果,SearchListView实现以及原理讲解
- 仿今日头条下拉出现SearchBar,再下拉刷新效果,SearchListView实现以及原理讲解
- iOS开发-UIWebView添加头部与尾部控件 && 仿iOS 今日头条新闻详情页结构实现
- Android 仿今日头条简单的刷新效果实例代码
- vue-- 今日头条 头部导航左右滑动效果
- 防止在listbox中添加很多数据出现不停的刷新
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- 动态地往datagirdview中添加数据,当所添加的数据超过datagridview的显示范围后,滚动条就无法显示,程序出现假死状态,(scrollbars=both)
- [转]使用showModalDialog打开模态窗口添加数据后刷新原窗口
- 使用showModalDialog打开模态窗口添加数据后刷新原窗口
- AjaxPanel自定义控件实现页面无刷新数据交互(做了个示例程序, 效果确实比较Cool, 用法非常简单! )(示例代码下载)
- ajax实现为table添加数据定时刷新
- 无刷新添加记录效果
- ListView控件刷新函数(添加,删除,修改数据时刷新)
- 基于Ajax:实时刷新数据,实时显示状态,局部刷新的示例。
- Struts中禁止刷新Action重复添加数据
- AJAX实时刷新数据、状态显示、局部刷新示例