Swift 设置完整集合ViewCell而不是图像的动画

Swift 设置完整集合ViewCell而不是图像的动画,swift,uicollectionviewcell,cabasicanimation,Swift,Uicollectionviewcell,Cabasicanimation,每当我按下edit按钮时,我都试图向我的collectionViewCells中添加一个抖动动画 我在StackOverFlow上找到了制作动画的代码: let cell : SettingsCollectionViewCell = mainCollectionView!.cellForItemAtIndexPath(indexpath) as! SettingsCollectionViewCell let shake:CABasicAnimation = CABasicAni

每当我按下
edit按钮时,我都试图向我的
collectionViewCells
中添加一个抖动动画

我在StackOverFlow上找到了制作动画的代码:

let cell : SettingsCollectionViewCell = mainCollectionView!.cellForItemAtIndexPath(indexpath) as! SettingsCollectionViewCell

        let shake:CABasicAnimation = CABasicAnimation(keyPath: "position")
        shake.duration = 0.1
        shake.repeatCount = 2
        shake.autoreverses = true


        let from_point:CGPoint = CGPointMake(cell.center.x - 5, cell.center.y)
        let from_value:NSValue = NSValue(CGPoint: from_point)

        let to_point:CGPoint = CGPointMake(cell.center.x + 5, cell.center.y)
        let to_value:NSValue = NSValue(CGPoint: to_point)

        shake.fromValue = from_value
        shake.toValue = to_value
        cell.layer.addAnimation(shake, forKey: "position")

当我在我的
cell.collectionImage
上尝试此操作时,它可以完美地工作,但在这种情况下,它不会在我的cell.collectionImage上工作。有什么想法吗?

诀窍是解决
UICollectionCell的
contentView

cell.collectionView.frame.center.x

它以什么方式不起作用?有动画吗?你把代码放在控制器的什么地方?我根本不用cell.layer来设置动画。我把代码放在一个按钮方法中。