Created
February 1, 2026 22:09
-
-
Save jacobsapps/89295471c7d127ee98cf7f00c32eac28 to your computer and use it in GitHub Desktop.
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
| func setPressed(_ pressed: Bool) { | |
| let baseColors: [CGColor] | |
| let highlightColors: [CGColor] | |
| let rimColor: CGColor | |
| if pressed { | |
| baseColors = [...]; highlightColors = [...] | |
| } else { | |
| baseColors = [...]; highlightColors = [...] | |
| } | |
| CATransaction.begin() | |
| CATransaction.setDisableActions(true) | |
| CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: .easeInEaseOut)) | |
| CATransaction.setAnimationDuration(1.0) | |
| if animated { | |
| let baseAnimation = CABasicAnimation(keyPath: "colors") | |
| baseAnimation.fromValue = baseGradient.colors | |
| baseAnimation.toValue = baseColors | |
| baseGradient.add(baseAnimation, forKey: "colors") | |
| let highlightAnimation = CABasicAnimation(keyPath: "colors") | |
| highlightAnimation.fromValue = highlightGradient.colors | |
| highlightAnimation.toValue = highlightColors | |
| highlightGradient.add(highlightAnimation, forKey: "colors") | |
| } | |
| baseGradient.colors = baseColors | |
| highlightGradient.colors = highlightColors | |
| CATransaction.commit() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment