Last active
August 12, 2020 23:23
-
-
Save twhitt14/7f10aaee2bd5d675f71e5a7126952e53 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 updateOutline(isShowing: Bool, animated: Bool) { | |
let toColor: UIColor = isShowing ? .systemBlue : .clear | |
let toWidth: CGFloat = isShowing ? 2 : 0 | |
let animationDuration = 0.2 | |
if animated { | |
let borderColorAnimation: CABasicAnimation = CABasicAnimation(keyPath: "borderColor") | |
borderColorAnimation.fromValue = layer.borderColor | |
borderColorAnimation.toValue = toColor.cgColor | |
borderColorAnimation.duration = animationDuration | |
layer.add(borderColorAnimation, forKey: "borderColor") | |
layer.borderColor = toColor.cgColor | |
let borderWidthAnimation: CABasicAnimation = CABasicAnimation(keyPath: "borderWidth") | |
borderWidthAnimation.fromValue = layer.borderWidth | |
borderWidthAnimation.toValue = toWidth | |
borderWidthAnimation.duration = animationDuration | |
layer.add(borderWidthAnimation, forKey: "borderWidth") | |
layer.borderWidth = toWidth | |
} else { | |
layer.borderColor = toColor.cgColor | |
layer.borderWidth = toWidth | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment