ios - Swift - RemoveAllAnimations() 在 UICollectionViewCell 类中不起作用

标签 ios swift xcode animation

我目前遇到的问题是 removeAllAnimations() 函数在我的自定义 UICollectionViewCell 类中不起作用。

数组 progressBar[] 包含多个 UIProgressView。我希望 progressBar 在调用某些内容时停止动画。但现在它只是继续动画。 我该如何解决这个问题?

第一个执行实际动画的函数

@objc func updateProgress() {
    if visibleCell == "TRUE" {
        DispatchQueue.main.async {
            if self.index < self.imagesTest.count /*images.count*/ {
                CATransaction.begin()
                CATransaction.setCompletionBlock {
                    self.index += 1
                    self.updateProgress()
                }
                UIView.animate(withDuration: self.time, delay: 0, options: .curveLinear, animations: {
                    self.progressBar[self.index].setProgress(1.0, animated: true)
                })
                CATransaction.commit()
            }
        }
    }
}

应该停止正在进行的动画的第二个函数

func stopUpdating() {
    progressBar[index].layer.removeAllAnimations()
}

最佳答案

一行代码即可实现

替换你的代码

func stopUpdating() {
    progressBar[index].layer.removeAllAnimations()
}

func stopUpdating() {
   progressBar[index].layer.speed = 0 
}

希望对你有帮助

关于ios - Swift - RemoveAllAnimations() 在 UICollectionViewCell 类中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47651889/

相关文章:

php - webservice接收参数数组作为字符串而不是数组

ios - 如果使用 CKFetchRecordZoneChangesOperation 时应用程序被终止,会发生什么?

swift - 我不小心拒绝了某些东西的 xcode 权限

iphone - 快速在每个 View Controller 上滑动菜单

iphone - 转到另一个选项卡并返回后,UITabBar 和 UIMenuControl 不会出现

ios - 如何让iOS应用防篡改?

ios - 将应用内购买收据数据发送到我的服务器

ios - Google SDK 在 Xcode 中记录两次

xcode - XCode 4.2 或 Coda 的 SVN 证书信任错误,但不是命令行或 svnX

ios - 未找到库 .h 文件