swift - tableView数据向上收缩动画
//
// 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
}
// 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
}
}
posted on 2015-12-11 12:36 taiyang2014 阅读(797) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步