Created
January 31, 2019 17:11
-
-
Save novinfard/5c048844273b80542e4f6ecb9085382e to your computer and use it in GitHub Desktop.
[Animate border of UIView by protocol implementation]
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
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