Add hover interaction to trending link cards
This commit is contained in:
parent
521e5ad5fc
commit
3262fe002b
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@
|
|||
</constraints>
|
||||
</view>
|
||||
<visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cWo-9n-z42">
|
||||
<rect key="frame" x="0.0" y="196.66666666666666" width="300" height="28.333333333333343"/>
|
||||
<rect key="frame" x="0.0" y="196.33333333333334" width="300" height="28.666666666666657"/>
|
||||
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="ktv-3s-cp9">
|
||||
<rect key="frame" x="0.0" y="0.0" width="300" height="28.333333333333343"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="300" height="29"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsLetterSpacingToFitWidth="YES" showsExpansionTextWhenTruncated="YES" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ho3-cU-IGi">
|
||||
|
|
Loading…
Reference in New Issue