gpt4 book ai didi

ios - 如何在我滚动时为 UICollectionview 单元格设置动画

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:45 29 4
gpt4 key购买 nike

如何在滚动时为水平 Collectionview 设置动画 我在单元格中将 alpha 更改为 0,在 cellForItemAt 中我将 alpha 设置为 1 的动画,但这仅在 Collectionview 滚动到第一个时发生时间是我试过的代码

UIView.animate(withDuration: 0.8) {
cell.imageView.alpha = 1
cell.onboardLabel.alpha = 1
}

我也尝试在 scrollViewDidEndDecelerating 中执行此操作,但仍然无法正常工作

 let index = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
let indexPath = IndexPath(item: index, section: 0)
let cell = collectionView.cellForItem(at: indexPath) as? OnboardingCell

UIView.animate(withDuration: 0.8) {
cell?.imageView.alpha = 1
cell?.onboardLabel.alpha = 1
}

最佳答案

swift 4:

从 UICollectionViewDelegate 使用这个函数:

 override func collectionView(_ collectionView: UICollectionView,
willDisplay cell: UICollectionViewCell,
forItemAt indexPath: IndexPath) {

cell.alpha = 0
UIView.animate(withDuration: 0.8) {
cell.alpha = 1
}
}

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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com