使用 UIDynamics 为 UICollectionView 设置动画 Swift
Animate UICollectionView with UIDynamics Swift
在 Apple 自己的文档中,它说明了如何构建该行为的步骤,但我不太明白,谁能告诉我如何在代码中做到这一点。
To animate collection views, create an animator with the init(collectionViewLayout:) method. The resulting animator employs a collection view layout (an object of the UICollectionViewLayout class) for its coordinate system. The dynamic items in this sort of animator must be UICollectionViewLayoutAttributes objects that are part of the layout.
You can define a boundary, for items participating in a collision behavior, relative to the bounds of the collection view layout. See the setTranslatesReferenceBoundsIntoBoundary(with:) method.
A collection view animator automatically calls the invalidateLayout() method as needed, and automatically pauses and resumes animation, as appropriate, when you change a collection view’s layout.
这有点过时了,但看起来是一个有趣的介绍:https://www.objc.io/issues/5-ios7/collection-views-and-uidynamics/
在 Apple 自己的文档中,它说明了如何构建该行为的步骤,但我不太明白,谁能告诉我如何在代码中做到这一点。
To animate collection views, create an animator with the init(collectionViewLayout:) method. The resulting animator employs a collection view layout (an object of the UICollectionViewLayout class) for its coordinate system. The dynamic items in this sort of animator must be UICollectionViewLayoutAttributes objects that are part of the layout. You can define a boundary, for items participating in a collision behavior, relative to the bounds of the collection view layout. See the setTranslatesReferenceBoundsIntoBoundary(with:) method. A collection view animator automatically calls the invalidateLayout() method as needed, and automatically pauses and resumes animation, as appropriate, when you change a collection view’s layout.
这有点过时了,但看起来是一个有趣的介绍:https://www.objc.io/issues/5-ios7/collection-views-and-uidynamics/