【问题标题】: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
            ...
        })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    相关资源
    最近更新 更多