Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save novinfard/5c048844273b80542e4f6ecb9085382e to your computer and use it in GitHub Desktop.
Save novinfard/5c048844273b80542e4f6ecb9085382e to your computer and use it in GitHub Desktop.
[Animate border of UIView by protocol implementation]
protocol PLAnimatableBorder {
func animateBorderWidth(toValue: CGFloat, duration: Double)
}
extension PLAnimatableBorder where Self: UIView {
/// animate the border width
func animateBorderWidth(toValue: CGFloat, duration: Double) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "borderWidth")
animation.fromValue = layer.borderWidth
animation.toValue = toValue
animation.duration = duration
layer.add(animation, forKey: "Width")
layer.borderWidth = toValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment