每当我按下 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
上尝试这个时,它工作得很好,但在本例中不是在我的单元本身上。有什么想法吗?
最佳答案
技巧是解决 UICollectionCell
的 contentView
cell.collectionView.frame.center.x
关于swift - 动画完成 Collection View Cell 而不是 Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35650077/