mik*_*sis 2 cell uitableview ios swift
当我显示表格视图时,我的单元格带有这样的动画。
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.alpha = 0
let rotation = CATransform3DTranslate(CATransform3DIdentity, -250, 20, 0)
cell.layer.transform = rotation
UIView.animateWithDuration(0.9){
cell.alpha = 1
cell.layer.transform = CATransform3DIdentity
}
Run Code Online (Sandbox Code Playgroud)
它的工作方式是这样,但是当我向下然后再次向上查看先前的单元时,动画仍然存在。
显示我相信我必须检查是否已显示该单元格。
我尝试的方法是使用didEndDisplayingCell函数并将cell.tag放入数组中,然后我使用array.contains(cell.tag)检查当前单元格是否在该数组中,但是它不起作用。实际上,该动画仅对前三个单元起作用,然后什么也没有。
您应该保留一个indexPaths数组,并在显示单元格时将其添加到其中。这样,您可以检查单元格是否已设置动画。
if (!indexPaths.contains(indexPath)) {
indexPaths.append(indexPath)
cell.alpha = 0
let rotation = CATransform3DTranslate(CATransform3DIdentity, -250, 20, 0)
cell.layer.transform = rotation
UIView.animateWithDuration(0.9){
cell.alpha = 1
cell.layer.transform = CATransform3DIdentity
}
}
Run Code Online (Sandbox Code Playgroud)