UICollectionView触摸时动画

时间:2016-12-23 02:33:02

标签: ios swift animation uicollectionview

当有人触摸UICollesctionView的Cell时,有人能指出正确的方向吗?我读过didSelectItemAt与UIView.Animate或willDisplayCell与CAAnimations之间有几种方法。有人可以指点我在Swift的正确方向吗?目标是点击单元格并使其缩放/更改x位置

1 个答案:

答案 0 :(得分:0)

我会选择" 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
            ...
        })
}