我目前遇到的问题是 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/