首页 > 其他 > 详细

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

时间:2016-02-24 18:55:51      阅读:416      评论:0      收藏:0      [点我收藏+]

首先附上效果图技术分享技术分享

 

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

 

代码“

//
//  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 = 0;i<5;i++)
    {
        [self.shouDatas addObject:[NSString stringWithFormat:@"%d",i]];
    }
    
    
    //对tableview进行设置
    _showTableView = [[UITableView alloc]initWithFrame:CGRectMake(100, 100,200 , 44)];
    [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 = 0;
    //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 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
#pragma mark-定时器的实现方法
-(void)scroll:(NSTimer*)sender
{
    if(self.shouDatas.count==self.count)
    {
        self.count=0;
    
        [self.showTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
                                        animated:NO
                                  scrollPosition:UITableViewScrollPositionBottom];
    }
    else
    {
        
        [self.showTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:self.count inSection:0]
                                        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

 

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

原文:http://www.cnblogs.com/lishanshan/p/5213664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!