如何检查一个单元格是否已经显示Swift(How to check if a cell has been displayed Swift)

系统教程 行业动态 更新时间:2024-06-14 17:02:17
如何检查一个单元格是否已经显示Swift(How to check if a cell has been displayed Swift)

当我显示我的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 } }

更多推荐

本文发布于:2023-04-21 18:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/808f624d3d3c87454df15e0ef14766a0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   Swift   check   cell   displayed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!