动画完整的CollectionViewCell而不是Image

时间:2016-02-26 11:04:56

标签: swift uicollectionviewcell cabasicanimation

每当我按下collectionViewCells时,我都会尝试向我的editButton添加动画动画。

我发现代码在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上尝试此操作时,它的效果非常好,但在这种情况下不在我的手机本身上。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

诀窍是解决contentView

UICollectionCell
cell.collectionView.frame.center.x