Improve highlight animation for item cells
This commit is contained in:
parent
f8026125cc
commit
83c3bc927e
|
@ -19,6 +19,7 @@ class ItemCollectionViewCell: UICollectionViewListCell {
|
||||||
private let feedTitleLabel = UILabel()
|
private let feedTitleLabel = UILabel()
|
||||||
private let contentLabel = UILabel()
|
private let contentLabel = UILabel()
|
||||||
private var shouldInteractOnNextTouch = true
|
private var shouldInteractOnNextTouch = true
|
||||||
|
var scrollView: UIScrollView?
|
||||||
|
|
||||||
private var item: Item!
|
private var item: Item!
|
||||||
|
|
||||||
|
@ -112,12 +113,16 @@ class ItemCollectionViewCell: UICollectionViewListCell {
|
||||||
guard shouldInteractOnNextTouch else { return }
|
guard shouldInteractOnNextTouch else { return }
|
||||||
shouldInteractOnNextTouch = false
|
shouldInteractOnNextTouch = false
|
||||||
feedbackGenerator.prepare()
|
feedbackGenerator.prepare()
|
||||||
UIView.animateKeyframes(withDuration: 0.4, delay: 0, options: .allowUserInteraction) {
|
|
||||||
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
|
// couldn't manage to do this with just the recognizers
|
||||||
self.backgroundColor = .appCellHighlightBackground
|
if scrollView?.isDragging == false && scrollView?.isDecelerating == false {
|
||||||
}
|
UIView.animateKeyframes(withDuration: 0.4, delay: 0, options: .allowUserInteraction) {
|
||||||
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
|
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
|
||||||
self.backgroundColor = nil
|
self.backgroundColor = .appCellHighlightBackground
|
||||||
|
}
|
||||||
|
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
|
||||||
|
self.backgroundColor = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +154,7 @@ private class DoubleTapRecognizer: UITapGestureRecognizer {
|
||||||
super.touchesBegan(touches, with: event)
|
super.touchesBegan(touches, with: event)
|
||||||
onTouchesBegan()
|
onTouchesBegan()
|
||||||
// shorten the delay before the single tap is recognized
|
// shorten the delay before the single tap is recognized
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(300)) { [weak self] in
|
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(400)) { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
if self.state != .recognized {
|
if self.state != .recognized {
|
||||||
self.state = .failed
|
self.state = .failed
|
||||||
|
|
|
@ -62,6 +62,7 @@ extension ItemsViewController: UICollectionViewDataSource {
|
||||||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "itemCell", for: indexPath) as! ItemCollectionViewCell
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "itemCell", for: indexPath) as! ItemCollectionViewCell
|
||||||
cell.delegate = self
|
cell.delegate = self
|
||||||
|
cell.scrollView = collectionView
|
||||||
cell.updateUI(item: resultsController.fetchedObjects![indexPath.row])
|
cell.updateUI(item: resultsController.fetchedObjects![indexPath.row])
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue