Man*_*oto 3 animation core-animation ios uicollectionview swift
一直试图在集合视图上为项目插入设置动画,动画是从屏幕外部从左到右或从右到左滑动,为此我正在更改项目的框架原点 x 值。
我的问题是当我调用 UIView.animate 时,完成回调被立即调用而不显示动画,我试图在项目的类中,在方法 collectionView(_:cellForItemAt:) 中添加动画代码,甚至尝试创建一个自定义 viewflowlayout 并覆盖 layoutAttributesForItemAtIndexPath 以添加转换,但没有任何工作,任何建议。
这有效:
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 1, animations: {
var newFrame = cell.frame
cell.frame = CGRect(x: newFrame.origin.x + 50, y: newFrame.origin.y, width: newFrame.width, height: newFrame.height)
})
}
Run Code Online (Sandbox Code Playgroud)
根据您的需要更换偏移量。
这也有效:
cell.frame.origin.x = cell.frame.origin.x + 50
Run Code Online (Sandbox Code Playgroud)
willDisplayCell 的内部
| 归档时间: |
|
| 查看次数: |
2941 次 |
| 最近记录: |