每当我按下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
上尝试此操作时,它的效果非常好,但在这种情况下不在我的手机本身上。有什么想法吗?
答案 0 :(得分:0)
诀窍是解决contentView
UICollectionCell
cell.collectionView.frame.center.x