Skip to content

Instantly share code, notes, and snippets.

@twhitt14
Last active August 12, 2020 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twhitt14/7f10aaee2bd5d675f71e5a7126952e53 to your computer and use it in GitHub Desktop.
Save twhitt14/7f10aaee2bd5d675f71e5a7126952e53 to your computer and use it in GitHub Desktop.
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