//
// 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
}
}