gpt4 book ai didi

ios - 如何在 collectionView 或 tableView 单元格中重复动画?

转载 作者:行者123 更新时间:2023-11-30 11:09:17 24 4
gpt4 key购买 nike

我的问题的简化版本是我试图在 collectionView 单元格内的按钮上循环/重复动画,但动画仅执行一次。这是我的动画 block ,位于我的 collectionViewCell 中:

func animateGlowingCircle() {
UIView.animate(withDuration: 1.0, delay: 0, options: [.autoreverse, .repeat], animations: {
self.glowCircle.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}, completion: nil)
}

我尝试从几个不同的地方调用 animateGlowingCircle():在 collectionViewController 的 viewDidLoad 或 cellForRowAt 中,以及从 collectionView 的绘制中。我能得到的最接近的是动画只执行一次但不循环。我在网上找到了大量有关单次执行动画的信息,但没有找到循环动画的信息。任何帮助将不胜感激!

最佳答案

弄清楚了:循环单元动画需要从collectionView Controller 的willDisplayCell方法中调用。所以像这样:

// In collectionViewController    
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
let timerCell = cell as! TimerCollectionViewCell
timerCell.animateGlowingCircle()
}


// In collectionViewCell (this is the same code posted with the question)
func animateGlowingCircle() {
UIView.animate(withDuration: 1.0, delay: 0, options: [.autoreverse, .repeat], animations: {
self.glowCircle.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}, completion: nil)
}

关于ios - 如何在 collectionView 或 tableView 单元格中重复动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52347171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com