首页 > 解决方案 > CollectionViewCell 效果

问题描述

有什么想法,如何从新的 Shortcuts 应用程序中为 collectionViewCells应用这种很酷的效果?

标签: iosswiftxcode

解决方案


您可以在 uiCollectionViewCell 类中简单地添加以下代码,并在 uiCollectionView 中查看效果。

class imgcollectioncell: UICollectionViewCell {

@IBOutlet weak var img: UIImageView!


override var isHighlighted: Bool{
    didSet{
        if isHighlighted{
            UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1.0, options: .curveEaseOut, animations: {
                self.transform = self.transform.scaledBy(x: 0.75, y: 0.75)
            }, completion: nil)
        }else{
            UIView.animate(withDuration: 0.5, delay: 0.0, usingSpringWithDamping: 0.4, initialSpringVelocity: 1.0, options: .curveEaseOut, animations: {
                self.transform = CGAffineTransform.identity.scaledBy(x: 1.0, y: 1.0)
            }, completion: nil)
        }
    }
}  


 }

我希望它会帮助你。


推荐阅读