我有一个动画功能,我在应用程序的许多其他部分使用它,它完美地工作:
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)
有什么想法吗?
答案 0 :(得分:2)
将您的代码更改为
let cell = collectionView.cellForItemAtIndexPath(indexPath)
您当前创建/出列新单元格而不是检索当前单元格。