gpt4 book ai didi

ios - 动画表格 View 单元格,包括标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:39:04 24 4
gpt4 key购买 nike

我使用以下方法为表格 View 的单元格设置动画:

func animateCells(tableView: UITableView) {
tableView.reloadData()

let cells = tableView.visibleCells
let tableHeight: CGFloat = tableView.bounds.size.height

for i in cells {
let cell: UITableViewCell = i as UITableViewCell
cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
}

var index = 0

for a in cells {
let cell: UITableViewCell = a as UITableViewCell
UIView.animateWithDuration(animationDuration, delay: animationDelay * Double(index),usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
cell.transform = CGAffineTransformMakeTranslation(0, 0);
}, completion: nil)

index += 1
}
}

这仅适用于表格 View 中的单元格。但我也有一些带有标题的表格,在这些情况下动画不起作用。如何在上面的动画代码中包含标题?谢谢。

最佳答案

解决了 tableView 部分标题动画的问题:

// animate section header
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let numberOfSections = tableView.numberOfSections
let tableHeight: CGFloat = tableView.bounds.size.height
var index = 0

for i in 0...numberOfSections - 1 {
if (section == i) {
view.transform = CGAffineTransformMakeTranslation(0, tableHeight)
UIView.animateWithDuration(1.0, delay: 0.05 * Double(index),usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { () -> Void in
view.transform = CGAffineTransformMakeTranslation(0, 0)
}, completion: nil)
}
index += 1
}
}

对于细胞:

// animate cells
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
let numberOfSections = tableView.numberOfSections
let tableHeight: CGFloat = tableView.bounds.size.height
var index = 0

for i in 0...numberOfSections - 1 {
let numberOfCells = tableView.numberOfRowsInSection(i)

for j in 0...numberOfCells - 1 {
if (indexPath.section == i && indexPath.row == j) {
cell.transform = CGAffineTransformMakeTranslation(0, tableHeight)
UIView.animateWithDuration(1.0, delay: 0.05 * Double(index),usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
cell.transform = CGAffineTransformMakeTranslation(0, 0);
}, completion: nil)
}
index += 1
}
}
}

感谢您的提示!

关于ios - 动画表格 View 单元格,包括标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35582198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com