我已经创建了一个自定义布局,并像这样在 layoutAttributesForItemAtIndexPath
中设置我的单元格位置属性
attributes.center = CGPointMake((size.width/2 - 100) + 100, (size.height/2 - 150) +100);
我想在选中时为单元格设置动画。复制我们使用 initialLayoutAttributesForAppearingItemAtIndexPath
和 finalLayoutAttributesForDisappearingItemAtIndexPath
获得的那种动画。
我想在选择和取消选择单元格时执行此操作。
例如:
单元格 A 位于位置 0,0
。单元格 B 位于 50,100
位置。如果我选择单元格 B,我想将其动画化为 0,0
。同时将单元格 A 设置为 50,100
。基本上是交换位置,但很生动。
最佳答案
也许是一种不同的方法。只需覆盖 collectionViewCell 中的 isSelected。
override var isHighlighted: Bool {
didSet {
if isHighlighted {
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
// animate highlight
}, completion: nil)
} else {
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
// animate unHighligh
}, completion: nil)
}
}
}
在这篇文章中 UICollectionView: Animate cell size change on selection您可以查看有关如何为大小更改设置动画的示例。
关于ios - 在选择时为 uicollectionview 单元格设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885003/