ios - 动画表格 View 单元格,包括标题
<p><p>我使用以下方法为表格 View 的单元格设置动画:</p>
<pre><code>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
}
}
</code></pre>
<p>这仅适用于表格 View 中的单元格。但我也有一些带有标题的表格,在这些情况下动画不起作用。如何在上面的动画代码中包含标题?谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>解决了 tableView 部分标题动画的问题:</p>
<pre><code>// 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
}
}
</code></pre>
<p>对于细胞:</p>
<pre><code>// 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
}
}
}
</code></pre>
<p>谢谢你的提示!!</p></p>
<p style="font-size: 20px;">关于ios - 动画表格 View 单元格,包括标题,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35582198/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35582198/
</a>
</p>
页:
[1]