ios - 在选择时为 uicollectionview 单元格设置动画

标签 ios ios6 uicollectionview uicollectionviewcell

我已经创建了一个自定义布局,并像这样在 layoutAttributesForItemAtIndexPath 中设置我的单元格位置属性

attributes.center = CGPointMake((size.width/2 - 100) + 100, (size.height/2 - 150) +100);
 

我想在选中时为单元格设置动画。复制我们使用 initialLayoutAttributesForAppearingItemAtIndexPathfinalLayoutAttributesForDisappearingItemAtIndexPath 获得的那种动画。

我想在选择和取消选择单元格时执行此操作。

例如:

单元格 A 位于位置 0,0。单元格 B 位于 50,100 位置。如果我选择单元格 B,我想将其动画化为 0,0。同时将单元格 A 设置为 50,100。基本上是交换位置,但很生动。

最佳答案

也许是一种不同的方法。只需覆盖 collectionViewCell 中的 isSelected。

 override var isHighlighted: Bool {
    didSet {
        if isHighlighted {
            UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
                // animate highlight
            }, completion: nil)
        } else {
            UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseOut, animations: {
                // animate unHighligh
            }, completion: nil)
        }
    }
}

在这篇文章中 UICollectionView: Animate cell size change on selection您可以查看有关如何为大小更改设置动画的示例。

关于ios - 在选择时为 uicollectionview 单元格设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885003/

相关文章:

ios6 - UICollectionViewCell 不显示任何内容

ios - 如何检查边界框是否包含我的观点

objective-c - iOS 6 通讯录清空 kABPersonPhoneProperty

ios - 您还没有注册任何设备 token - Urban Airship

ios - 如何使用 UICollectionViewFlowLayout 将集合中的每个 View 居中?

ios - 具有自定义布局的 UICollectionView 界面旋转

iPhone开发: launching app on receiving push notification

xcode - Xcode 中的预期标识符?我需要帮助!

ios - 如何创建开发/暂存/生产环境

ios - 整个应用程序为 "Handle No Internet"