我只是想在以编程方式滚动到项目时制作自定义动画。因此,当我不编写动画并按单元格使用默认值时,不会消失,但是当我将 scrolltoItem func 放入 UIView.animate func 时,最后一个单元格首先消失,然后 scrollToItem 动画。 在最上面的第二张图片中,位于独立游戏单元格之前的 collectionView 首先消失,然后 collectionView 从独立游戏单元格滚动到下一个
为什么会发生这种行为?为什么当我不以我的方式有目的地对其进行动画处理,而只是使用 animated = true func 调用 scrollToItem 时,什么都没有消除?如果有人知道细胞发生了什么,请给我一个线索。
UIView.animate(withDuration: 10, delay: 0, options: .curveEaseInOut, animations: {
self.appsCollectionView.scrollToItem(at: IndexPath(item: self.actualNumberOfTheCell, section: 0), at: .centeredHorizontally, animated: false)
}, completion: nil)
最佳答案
我认为你应该使用 self.view.layoutIfNeeded()
self.appsCollectionView.scrollToItem(at: IndexPath(item: self.actualNumberOfTheCell, section: 0), at: .centeredHorizontally, animated: false)
UIView.animate(withDuration: 10, delay: 0, options: .curveEaseInOut, animations: {
self.view.layoutIfNeeded()
}, completion: nil)
希望能成功
关于ios - 当我设置动画(使用我的自定义动画)scrollToItem 函数时,UICollectionView 单元格消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49818021/