Created
April 5, 2021 10:51
-
-
Save ytyubox/339fc0514e2ac4817b7bc3389943005d to your computer and use it in GitHub Desktop.
Tap To Squeeze On Cell and Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Also working with UIControl, UITableViewCell */ | |
class Cell: UICollectionViewCell { | |
override var isHighlighted: Bool { | |
didSet { | |
let duration = isHighlighted | |
? 0.45 | |
: 0.4 | |
let transform = isHighlighted | |
? CGAffineTransform(scaleX: 0.96, y: 0.96) | |
: CGAffineTransform.identity | |
let bgColor = isHighlighted | |
? UIColor(white: 1.0, alpha: 0.2) | |
: UIColor(white: 1.0, alpha: 0.1) | |
let animations = { | |
self.transform = transform | |
self.bgView.backgroundColor = bgColor | |
} | |
UIView.animate(withDuration: duration, | |
delay: 0, | |
usingSpringWithDamping: 1.0, | |
initialSpringVelocity: 0.0, | |
options: [.allowUserInteraction, .beginFromCurrentState], | |
animations: animations, | |
completion: nil) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment