簡體   English   中英

我無法設置UICollectionViewCell子類或其任何子視圖的動畫

[英]I can't animate UICollectionViewCell subclass or any of it's subviews

我有一個動畫功能,可以在應用程序的許多其他部分中使用它,並且效果很好:

class func pulse(view: UIView, sizeMultiplier: Float, duration: NSTimeInterval, repeatCount: Float = 1.0) {
    let pulseAnimation = CABasicAnimation(keyPath: "transform.scale")
    pulseAnimation.duration = duration
    pulseAnimation.toValue = NSNumber(float: sizeMultiplier)
    pulseAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    pulseAnimation.autoreverses = true
    pulseAnimation.repeatCount = repeatCount
    view.layer.addAnimation(pulseAnimation, forKey: nil)
}

但是由於某種原因,我無法為UICollectionView的單元設置動畫

在我的didSelectItemAtIndexPath函數中(該函數正在調用,我使用斷點進行了檢查),具有以下功能:

let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! ModuleCell        
Animations.pulse(cell, sizeMultiplier: 2.0, duration: 0.2, repeatCount: 2)

有任何想法嗎?

將您的代碼更改為

let cell = collectionView.cellForItemAtIndexPath(indexPath)

您當前正在創建/出隊新的單元格,而不是檢索當前的單元格。

暫無
暫無

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

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