我正在尝试在初始加载时为表格 View 单元格设置动画。动画适用于所有单元格,除了表格底部的最后一个单元格拒绝动画。
这是因为 UITableView.visibleCells
最后没有返回这个单元格。 (它返回单元格 0-12,最后一个单元格在索引 13 处并且清晰可见)
这是代码。我能做些什么来确保所有单元格都具有动画效果吗?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
let cells = tableView.visibleCells
let tableHeight: CGFloat = clubsTable.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(1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
cell.transform = CGAffineTransformMakeTranslation(0, 0);
}, completion: { (complete) in
})
index += 1
}
}
最佳答案
那是因为你的表格高度小于13个单元格的高度。因此它激活了 12 个单元格。您可以做的是将表格高度增加 30 像素(或任何像素,直到它包含 13 个单元格),并在动画完成后,将 tableView 的高度更改回正常。
关于ios - UITableView.visibleCells 未捕获所有可见单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38462213/