菜鸟教程小白 发表于 2022-12-11 18:23:37

ios - UICollectionView 触摸时动画


                                            <p><p>有人能指出我在触摸 UICollesctionView 的 Cell 时如何为它设置动画的正确方向吗?我读过在 didSelectItemAt 与 UIView.Animate 或 willDisplayCell 与 CAAnimations 之间有几种方法。有人可以指出我在 Swift 中的正确方向吗?目标是点击单元格并使其缩放/更改 x 位置</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我会选择“didSelectItemAt”,带有“UIView.animate”</p>

<pre><code>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
            ...
      })
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UICollectionView 触摸时动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41294459/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41294459/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UICollectionView 触摸时动画