From 3262fe002b871c774b2b14fe67a25f130a6c9200 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 22 Jan 2023 17:37:41 -0500 Subject: [PATCH] Add hover interaction to trending link cards --- .../TrendingLinkCardCollectionViewCell.swift | 26 +++++++++++++++++-- .../TrendingLinkCardCollectionViewCell.xib | 4 +-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift index c3cc229193..f9fdad85e2 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift @@ -22,6 +22,8 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { @IBOutlet weak var activityLabel: UILabel! @IBOutlet weak var historyView: TrendHistoryView! + private var hoverGestureAnimator: UIViewPropertyAnimator? + override func awakeFromNib() { super.awakeFromNib() @@ -32,6 +34,8 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { updateLayerColors() NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil) + + addGestureRecognizer(UIHoverGestureRecognizer(target: self, action: #selector(hoverRecognized))) } override func layoutSubviews() { @@ -138,12 +142,30 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { private func updateLayerColors() { if traitCollection.userInterfaceStyle == .dark { -// clippingView.layer.borderColor = UIColor.darkGray.withAlphaComponent(0.5).cgColor layer.shadowColor = UIColor.darkGray.cgColor } else { -// clippingView.layer.borderColor = UIColor.lightGray.withAlphaComponent(0.5).cgColor layer.shadowColor = UIColor.black.cgColor } } + // MARK: Interaction + + @objc private func hoverRecognized(_ recognizer: UIHoverGestureRecognizer) { + switch recognizer.state { + case .began, .changed: + hoverGestureAnimator = UIViewPropertyAnimator(duration: 0.2, curve: .easeInOut, animations: { + self.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) + }) + hoverGestureAnimator!.startAnimation() + case .ended: + hoverGestureAnimator?.stopAnimation(true) + hoverGestureAnimator?.addAnimations { + self.transform = .identity + } + hoverGestureAnimator?.startAnimation() + default: + break + } + } + } diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib index 8549f22bdb..53111e9bb5 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib @@ -56,9 +56,9 @@ - + - +