【问题标题】:UICollectionView Animate when touchedUICollectionView 触摸时动画
【发布时间】:2016-12-23 02:33:02
【问题描述】:
有人能指出我在触摸 UICollesctionView 的 Cell 时如何为它设置动画的正确方向吗?我读过在 didSelectItemAt 与 UIView.Animate 或 willDisplayCell 与 CAAnimations 之间有几种方法。有人可以指出我在 Swift 中的正确方向吗?目标是点击单元格并使其缩放/更改 x 位置
【问题讨论】:
标签:
ios
swift
animation
uicollectionview
【解决方案1】:
我会选择“didSelectItemAt”,带有“UIView.animate”
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
let cell = collectionView.cellForItem(at: indexPath)
animatedImage = UIImageView(frame: cell.frame)
animatedImage.image = ...
view.addSubview(animatedImage)
UIView.animate(withDuration: 0.5, animations: {
self.animatedImage.frame = self.view.bounds
self.view.layoutIfNeeded()
}, completion: {(finished) in
...
})
}