Collectionview动画

时间:2016-05-30 10:06:59

标签: ios swift animation layout uicollectionview

我有项目的集合视图,每个项目都有水平流量的尺寸(65 * 65),我有按钮。

因此,当我点击按钮时,所有项目必须叠加在第一个项目上,然后我需要垂直制作集合布局(如表格视图)。

如何制作(带动画)?

func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        if self.isClose {
            return CGSizeMake(50, 50)
        }else{
            if self.isOpen {
                return CGSizeMake(320, 50)
            }else {
                return CGSizeMake(50, 50)
            }
        }

    }

Screenshot

1 个答案:

答案 0 :(得分:0)

在Swift 3和4中

func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
    UIView.animate(withDuration: 0.5) {
        if let cell = collectionView.cellForItem(at: indexPath) as? SSProductCell {
            cell.imageView.transform = .init(scaleX: 0.95, y: 0.95)
            cell.contentView.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1)
        }
    }
}

func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {
    UIView.animate(withDuration: 0.5) {
        if let cell = collectionView.cellForItem(at: indexPath) as? SSProductCell {
            cell.imageView.transform = .identity
            cell.contentView.backgroundColor = .clear
        }
    }
}