swift - 动画完成 Collection View Cell 而不是 Image

标签 swift uicollectionviewcell cabasicanimation

每当我按下 editButton 时,我都会尝试向我的 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 上尝试这个时,它工作得很好,但在本例中不是在我的单元本身上。有什么想法吗?

最佳答案

技巧是解决 UICollectionCellcontentView

cell.collectionView.frame.center.x

关于swift - 动画完成 Collection View Cell 而不是 Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35650077/

相关文章:

ios - 如何获取位于 UICollectionView 中心的单元格的 indexPath

ios - 我的 UICollectionViewCell 项为零?

ios - 使用 SKShapeNode 像棒球棒一样进行触摸移动击球的最佳方式是什么?

ios - 核心 Spotlight API - 搜索结果中的 kUTTypeAudio 播放按钮

ios - Realm :重新排列对象列表

ios - CAShapeLayer() 绘制奇怪的线条/路径

ios - 根据随机 CGFloat 值重新绘制 UIBezierPath

swift - 检索最佳成绩 Game Center Swift

ios - UICollectionView cellForItem(在 :) crashes

iphone - iOS 旋转动画在 CAAnimationGroup 中发生不顺利