簡體   English   中英

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

[英]Swift - RemoveAllAnimations() doesn't work in an UICollectionViewCell class

我目前遇到的問題是,removeAllAnimations()函數在我的自定義UICollectionViewCell類中不起作用。

數組progressBar []包含多個UIProgressViews。 我希望在調用某些東西時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 
}

希望對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM