效果类似于label从下往上滑(采用uiTableView实现)

时间:2023-03-09 17:12:43
效果类似于label从下往上滑(采用uiTableView实现)

首先附上效果图效果类似于label从下往上滑(采用uiTableView实现)效果类似于label从下往上滑(采用uiTableView实现)

进行描述一下:效果就是类似于是一个竖直方向的滚动视图 并且方向是从下往上  并且能够一直这样循环下去。

代码“

//
// ViewController.m
// demo滚动视图上下
//
// Created by TaoLi on 16/2/24.
// Copyright © 2016年 TaoLi. All rights reserved.
// #import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *showTableView;
@property(nonatomic,strong)NSMutableArray *shouDatas;
@property(nonatomic,strong)UIView *testView;
@property(nonatomic,assign)CGFloat count;
@property(nonatomic,strong)NSTimer *myTimer;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //对数据进行设置
_shouDatas = [[NSMutableArray alloc]init];
for(int i = ;i<;i++)
{
[self.shouDatas addObject:[NSString stringWithFormat:@"%d",i]];
} //对tableview进行设置
_showTableView = [[UITableView alloc]initWithFrame:CGRectMake(, , , )];
[self.showTableView setSeparatorColor:[UIColor blueColor]];
//[self.showTableView setSeparatorStyle:];
self.showTableView.delegate = self;
self.showTableView.dataSource = self;
[self.view addSubview:self.showTableView]; self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(scroll:) userInfo:nil repeats:YES]; self.count = ;
//self.sumCount =[UIScreen mainScreen].bounds.size.height/40; }
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
{
[self.showTableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionBottom animated:YES];
} //设置每行的单元格的内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//1.根据reuseIdentifier,先到对象池中去找重用的单元格对象
static NSString *reuseIdentifier = @"Cell";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; //2.如果没找到,自己创建单元格对象
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
cell.textLabel.text = self.shouDatas[indexPath.row];
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.shouDatas.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
}
#pragma mark-定时器的实现方法
-(void)scroll:(NSTimer*)sender
{
if(self.shouDatas.count==self.count)
{
self.count=; [self.showTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow: inSection:]
animated:NO
scrollPosition:UITableViewScrollPositionBottom];
}
else
{ [self.showTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:self.count inSection:]
animated:YES
scrollPosition:UITableViewScrollPositionTop];
} self.count++; }
-(void)viewWillAppear:(BOOL)animated
{
// //开启定时器
[self.myTimer setFireDate:[NSDate distantPast]];
} //页面消失,进入后台不显示该页面,关闭定时器
-(void)viewDidDisappear:(BOOL)animated
{
//关闭定时器
[self.myTimer setFireDate:[NSDate distantFuture]];
} @end