【问题标题】:Collectionview animatedCollectionview 动画
【发布时间】:2016-09-28 02:58:24
【问题描述】:

我有项目的集合视图,每个项目都有水平流动的尺寸(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

【问题讨论】:

  • 你想如何准确地执行动画?他们应该以某种模式移动还是只从他们所在的位置开始第一个项目?
  • 喜欢这张图片 (i.stack.imgur.com/nTNvV.png)
  • 尝试为每一个删除ItemsAtIndexPaths,这样一段时间后我就会有一个项目
  • 如何将版面制作成专辑???

标签: ios swift animation layout uicollectionview


【解决方案1】:

在 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
        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多