cell实现跑马灯效果
来源:互联网 发布:明通网络数码科技 编辑:程序博客网 时间:2024/06/01 07:54
#import "ViewController.h"
@interface
ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property
(weak,
nonatomic
)
IBOutlet
UITableView *testTableView;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*bottomLine;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*topLine;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*topLine2;
@property
(weak,
nonatomic
)
IBOutlet
NSLayoutConstraint
*bottomLine2;
@property
(strong,
nonatomic
) CADisplayLink *displayLink;
@property
(assign,
nonatomic
)
int
count;
@property
(strong,
nonatomic
)
NSArray
*dataArray;
@end
@implementation
ViewController
- (
void
)viewDidLoad {
[
super
viewDidLoad];
self
.count = 0;
self
.testTableView.delegate =
self
;
self
.testTableView.dataSource =
self
;
self
.displayLink = [CADisplayLink displayLinkWithTarget:
self
selector:
@selector
(tick:)];
[
self
.displayLink addToRunLoop:[
NSRunLoop
currentRunLoop]
forMode:
NSDefaultRunLoopMode
];
//测试数据----->将需要展示的数据进行拼接,比如需要展示的数据数组为 @[@"1",@"2",@"3",@"4",@"5"] 那么需要拼接新数组 为 @[@"1",@"2",@"3",@"4",@"5",@"1",@"2",@"3",@"4",@"5"],示例如下
self
.dataArray = [
NSArray
arrayWithObjects:
@"1"
,
@"2"
,
@"3"
,
@"4"
,
@"5"
,
@"1"
,
@"2"
,
@"3"
,
@"4"
,
@"5"
,
nil
];
[
self
.testTableView setContentOffset:CGPointMake(0, 0) animated:
YES
];
self
.testTableView.userInteractionEnabled =
NO
;
}
//CADisplayLink 定时器 系统默认每秒调用60次
- (
void
) tick:(CADisplayLink *)displayLink {
self
.count ++;
//(25.0 / 30.0) * (float)self.count) ---> (tableview需要滚动的contentOffset / 一共调用的次数) * 第几次调用
//比如该demo中 contentOffset最大值为 = cell的高度 * cell的个数 ,5秒执行一个循环则调用次数为 300,没1/60秒 count计数器加1,当count=300时,重置count为0,实现循环滚动.
[
self
.testTableView setContentOffset:CGPointMake(0, ((25.0 / 30.0) * (
float
)
self
.count)) animated:
NO
];
if
(
self
.count >= 300) {
self
.count = 0;
}
}
- (
void
)didReceiveMemoryWarning {
[
super
didReceiveMemoryWarning];
}
- (
NSInteger
)tableView:(UITableView *)tableView numberOfRowsInSection:(
NSInteger
)section {
return
self
.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(
NSIndexPath
*)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"cell"
];
if
(cell ==
nil
) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
@"cell"
];
}
cell.textLabel.text =
self
.dataArray[indexPath.row];
cell.backgroundColor = [UIColor clearColor];
return
cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(
NSIndexPath
*)indexPath {
return
50;
}
- (
void
)dealloc {
[
self
.displayLink invalidate];
self
.displayLink =
nil
;
}
@end
0 0
- cell实现跑马灯效果
- JavaScript实现跑马灯效果
- iOS实现跑马灯效果
- C#实现跑马灯效果
- C#实现跑马灯效果 .
- TextView实现跑马灯效果
- android实现跑马灯效果
- TextView实现跑马灯效果
- JS实现跑马灯效果
- JS 实现跑马灯效果
- js实现跑马灯效果
- TextView实现跑马灯效果
- android实现跑马灯效果
- iOS实现跑马灯效果
- NSImageView 实现跑马灯效果
- TextView实现跑马灯效果
- TextView实现跑马灯效果
- Android跑马灯效果实现
- BZOJ 3036 绿豆蛙的归宿
- 自定义侧滑出现的问题及解决
- tomcat将端口8080改80方法
- spring TypeConverter (一)
- elasticsearch 查询(match和term)
- cell实现跑马灯效果
- Struts Problem Report
- NSArrayController绑定NSTableView的方法
- SSH 的详细使用方法
- poj-1276-Cash Machine
- dcloud开发app手势登录,oppo手机需要点一下才显示手势画板的问题
- ngDialog 一个简单的AngularJS模态框模板
- for each循环取值后多条修改提交至后台(SSH框架)
- 日志管理以及时间同步