12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // XMGRoolLinghtVIew.m
- // testTableVIew
- //
- // Created by 123 on 2020/4/30.
- // Copyright © 2020 DR. All rights reserved.
- //
- #import "XMGRoolLinghtVIew.h"
- @interface XMGRoolLinghtVIew()<UITableViewDelegate,UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (strong, nonatomic) CADisplayLink *displayLink;
-
- @property (assign,nonatomic) int count;
- @end
- @implementation XMGRoolLinghtVIew
-
- -(void)setDataArr:(NSMutableArray *)dataArr{
-
- _dataArr=dataArr;
-
- [self.tableView reloadData];
- }
- -(void)awakeFromNib{
- [super awakeFromNib];
- self.count = 0;
- _dataArr=[NSMutableArray array];
- self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- self.tableView.delegate=self;
- self.tableView.dataSource=self;
- self.layer.cornerRadius=5;
- self.layer.masksToBounds=YES;
-
- 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.tableView setContentOffset:CGPointMake(0, 10) animated:YES];
- self.tableView.userInteractionEnabled = NO;
- //_dataArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"1",@"2",@"3",@"4",@"5", nil];
-
-
- }
- +(instancetype)XIBXMGRoolLinghtView{
-
- return [[NSBundle mainBundle] loadNibNamed:@"XMGRoolLinghtVIew" owner:nil options:nil].firstObject;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 30;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return _dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- packageRoolCell *cell = [packageRoolCell cellWithTableView:tableView];
-
- packageRoolModel *model=_dataArr[indexPath.row];
-
- cell.model=model;
-
-
- return cell;
-
- }
- //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.tableView setContentOffset:CGPointMake(0, ((15.0 / 30.0) * (float)self.count)) animated:NO];
-
- if (self.count >= 150) {
-
- self.count = 0;
- }
- }
- - (void)dealloc {
-
- [self.displayLink invalidate];
- self.displayLink = nil;
-
- }
- @end
|