当我显示我的tableview时,我已经让我的单元格带有这样的动画。
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 }它是这样工作但当我下来然后再次看到以前的单元格动画仍然存在。
显示我相信我必须检查单元格是否已显示。
我尝试的是使用didEndDisplayingCell函数并将cell.tag放入一个数组中,然后我检查当前单元格是否在array.contains(cell.tag)的数组内,但它不起作用。 实际上这个动画只为三个第一个单元格工作,然后什么也没有。
When I display my tableview I've made my cells come with an animation like this.
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 }It's working like this but when i go down and then up again to see the previous cells the animation still exists.
Show I believe I have to check if the cell has been displayed.
Something I try is to use didEndDisplayingCell function and put the cell.tag inside an array and then I was checking if the current cell is inside that array with array.contains(cell.tag) but it didn't work. Actually the animation worked only for the three first cells and then nothing.
最满意答案
你应该保存一个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 } }You should keep an array of indexPaths, adding to it whenever a cell is displayed. This way you can check if the cell has already animated.
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 } }更多推荐
发布评论