当视图被 tableview 回收时,如何保持 lottie 动画运行? [英] How to keep lottie animation running when the view is recycled by a tableview?

查看:28
本文介绍了当视图被 tableview 回收时,如何保持 lottie 动画运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView 有很多不同的自定义单元格 1 其中有一个 Lottie 动画视图,当我按下按钮或收到某些网络消息时,动画应该跳到特定位置/前进,然后向前或向后动画.

I have a UITableView with plenty of different custom cells 1 of those has a lottie animation view and when I press a button or receive certain network messages the animation is supposed to jump to a specific position/progress and then animate either forward or backward.

到目前为止,一切都很好,直到我向下滚动并且 UITableViewCell 被回收,这会停止我的动画并且我无法跟踪正确的位置/进度.

So far, so good, all of this is working properly until I scroll down and the UITableViewCell gets recycled which stops my animation and I lose track of the proper position/progress.

我曾考虑过使用计时器并尝试将其与动画进度同步,或者实例化隐藏的 LottieAnimationView 并将其与可见的同步.有没有人处理过这个问题?有什么建议吗?

I've thought about maybe using a timer and trying to sync it with the animation progress or maybe instantiate a hidden LottieAnimationView and syncing it with the visible one. Has anyone dealt with this problem before? Any suggestions?

更新:有关更多详细信息,它需要在多个设备之间同步窗帘/门的相当长的动画,每当窗帘改变方向时,服务器都会向每个客户端发送一条消息,该消息包括方向(打开,关闭或停止)及其位置为 0% 到 100%(关闭到打开)

Update: For more details its a fairly long animation of a Curtain/Door that needs to be synced across multiple devices, the server sends me a message to each client whenever the curtain changes direction, the message includes the direction (open, closed or stopped) and its position as a percentage 0% to 100% (closed to open)

推荐答案

首先你应该知道哪个单元是你的动画单元,并且你不应该让那个单元出列.您将在控制器中创建该单元格,以便永远不会从您的 UITableView 重新初始化动画单元格.

First of all you should know which cell is your animation cell and you should not dequeue that cell. You will create that cell in your controller so animation cell will never be reinitialized from your UITableView.

    let animationCell = AnimationCell()

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       if indexPath.row == 0 { //0 is the animation cell
         return animationCell
        } else { 
         // try to dequeue your regular cell
        }
    }

这篇关于当视图被 tableview 回收时,如何保持 lottie 动画运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆