OGeek|极客世界-中国程序员成长平台

标题: ios - UICollectionView 触摸时动画 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:23
标题: ios - UICollectionView 触摸时动画

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



Best Answer-推荐答案


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

关于ios - UICollectionView 触摸时动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41294459/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4