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 contentLabel = UILabel()
|
||||
private var shouldInteractOnNextTouch = true
|
||||
var scrollView: UIScrollView?
|
||||
|
||||
private var item: Item!
|
||||
|
||||
|
@ -112,6 +113,9 @@ class ItemCollectionViewCell: UICollectionViewListCell {
|
|||
guard shouldInteractOnNextTouch else { return }
|
||||
shouldInteractOnNextTouch = false
|
||||
feedbackGenerator.prepare()
|
||||
|
||||
// couldn't manage to do this with just the recognizers
|
||||
if scrollView?.isDragging == false && scrollView?.isDecelerating == false {
|
||||
UIView.animateKeyframes(withDuration: 0.4, delay: 0, options: .allowUserInteraction) {
|
||||
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
|
||||
self.backgroundColor = .appCellHighlightBackground
|
||||
|
@ -121,6 +125,7 @@ class ItemCollectionViewCell: UICollectionViewListCell {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func cellDoubleTapped() {
|
||||
setRead(!item.read, animated: true)
|
||||
|
@ -149,7 +154,7 @@ private class DoubleTapRecognizer: UITapGestureRecognizer {
|
|||
super.touchesBegan(touches, with: event)
|
||||
onTouchesBegan()
|
||||
// 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 }
|
||||
if self.state != .recognized {
|
||||
self.state = .failed
|
||||
|
|
|
@ -62,6 +62,7 @@ extension ItemsViewController: UICollectionViewDataSource {
|
|||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "itemCell", for: indexPath) as! ItemCollectionViewCell
|
||||
cell.delegate = self
|
||||
cell.scrollView = collectionView
|
||||
cell.updateUI(item: resultsController.fetchedObjects![indexPath.row])
|
||||
return cell
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue