博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
swift - tableView数据向上收缩动画
阅读量:6963 次
发布时间:2019-06-27

本文共 1542 字,大约阅读时间需要 5 分钟。

//
//  TTTableViewController.swift
//  tableVIewAnimation
//
//  Created by su on 15/12/11.
//  Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class TTTableViewController: UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        //重载一下数据
        tableView.reloadData()
        //动画延时
        let diff = 0.05
        //获取tableview的高
        let tableHeight = self.tableView.bounds.size.height
        //获取所有的单元格
        let cells:[UITableViewCell] = self.tableView.visibleCells as [UITableViewCell]
        //遍历单元格
        for cell in cells {
            cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
        }
        //遍历cell顺序执行上移的动画
        for i in 0..<cells.count {
            let cell:UITableViewCell = cells[i] as UITableViewCell
            //根据序列号决定延时时间
            let delay = diff * Double(i)
            //执行动画
            UIView.animateWithDuration(1, delay: delay, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                //重新回到原始位置
                cell.transform = CGAffineTransformMakeTranslation(0, 0)
                }, completion: nil)
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      
        return 20
    }
 
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
       
        cell.textLabel?.text = "数据:\(indexPath.row)"
        cell.detailTextLabel?.text = "数据\(indexPath.row)"
        return cell
    }
  
}

转载于:https://www.cnblogs.com/tian-sun/p/5038647.html

你可能感兴趣的文章
ffmpeg+ffserver搭建流媒体服务器
查看>>
GitHub使用教程for Eclipse
查看>>
[再寄小读者之数学篇](2014-05-30 有限无界函数)
查看>>
HTML5----CSS显示半个字符
查看>>
Paxos算法之旅(四)zookeeper代码解析--转载
查看>>
Java多线程之新类库中的构件PriorityBlockingQueue
查看>>
面向对象程序设计与面向过程程序设计解析
查看>>
H TML5 之 (5) 一个在线画图板
查看>>
linux内存操作----kernel 3.5.X copy_from_user()和copy_to_user()
查看>>
c++经典排序算法全集(转)
查看>>
nginx 负载均衡示例
查看>>
[原]巧用RenderTexture
查看>>
android:layout_gravity="bottom"不起作用问题
查看>>
Linux用户态程序计时方式详解
查看>>
转:dll文件解读
查看>>
博客园博客停止更新的通知,程序员生存定律会在CSDN发完
查看>>
模仿SDWebImage实现异步加载图片
查看>>
#define barrier() __asm__ __volatile__("": : :"memory") 中的memory是gcc的东西
查看>>
JAVA SE 框架之俄罗斯方块的效果
查看>>
C#正则表达式获取组名,按照组名输出匹配内容
查看>>