【问题标题】:How to change the default layout animation curve in a custom UICollectionView layout engine?如何更改自定义 UICollectionView 布局引擎中的默认布局动画曲线?
【发布时间】:2016-02-08 12:02:23
【问题描述】:

我有一个集合视图设置,可以使用自定义集合视图布局运行。我可以通过更改 UICollectionViewLayoutAttributes 上的转换和 alpha 来设置单元格出现和消失的动画,但是,我想将动画曲线更改为使用弹簧 + 阻尼,以使单元格在出现时“弹跳”。

有人知道我如何实现这一目标吗?

谢谢,

【问题讨论】:

标签: ios swift uicollectionview uicollectionviewlayout


【解决方案1】:

将 UICollectionView 的 deleteItems/insertItems/reloadItems 调用封装在 UIView.animateWithDuration:delay:options:animations:completion: 调用中。

例子:

let duration = 0.25 // Hardcoded keyboard animation duration and curve
let curve = UIViewAnimationOptions(rawValue: 7 << 16) // ↑
UIView.animate(withDuration: duration, delay: 0, options: curve, animations: ({ [weak self] in
    self?.collectionView?.performBatchUpdates({
        self?.collectionView?.deleteItems(at: deletedIPs)
        self?.collectionView?.insertItems(at: insertedIPs)
        self?.collectionView?.reloadItems(at: updatedIPs)
    }, completion: nil)
}), completion: nil)

【讨论】:

    猜你喜欢
    • 2016-01-31
    • 2012-10-11
    • 1970-01-01
    • 2015-03-29
    • 1970-01-01
    • 2015-07-07
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多