【发布时间】:2019-06-17 19:59:06
【问题描述】:
我有下面的代码,它成功地导致collectionView 中的单元格在被点击时被按下。
问题是,在萧条发生之前,人们必须坚持很长时间。不要误会我的意思。它只有大约 1 秒,但如果你将该速度与 snapchat 的速度进行比较,你可以清楚地看到 snapchat 几乎是即时的。
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 0.1, animations: {
collectionView.cellForItem(at: indexPath)!.transform = CGAffineTransform.identity.scaledBy(x: 0.95, y: 0.95)
})
}
问题:我怎样才能为每个单元格制作这个动画,是即时的还是更接近它,就像 snapchat 一样?
更新:
这似乎是这样做的:
func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
UIView.animate(withDuration: 0.1, animations: {
collectionView.cellForItem(at: indexPath)!.transform = CGAffineTransform.identity.scaledBy(x: 0.95, y: 0.95)
}) { (true) in
UIView.animate(withDuration: 0.1, animations: {
collectionView.cellForItem(at: indexPath)!.transform = CGAffineTransform.identity.scaledBy(x: 1, y: 1)
})
}
}
如果有人想要一些基本的东西,这是一个选项。
【问题讨论】:
-
@canister_exister,不,放手后运行。上面的方法在用户按住时运行,因为那是它需要启动的时候。
-
使用 didHighlightItemAt 的原因是什么?
标签: ios swift uicollectionview cell tap