Skip to content

Instantly share code, notes, and snippets.

@budidino
Last active February 20, 2021 18:37
Show Gist options
  • Save budidino/af1edcb204bcf94874680e1a1b125461 to your computer and use it in GitHub Desktop.
Save budidino/af1edcb204bcf94874680e1a1b125461 to your computer and use it in GitHub Desktop.
Useful UIView extensions for animating views - usually used when UIView is updated or interacted with
extension UIView {
func springIn(duration: TimeInterval = 0.5, delay: Double = 0, fromScale: CGFloat = 0.6) {
self.layer.removeAllAnimations()
self.alpha = 1
self.transform = CGAffineTransform(scaleX: fromScale, y: fromScale)
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: 0.5, initialSpringVelocity: 3.0, options: [.curveEaseInOut, .allowUserInteraction], animations: {
self.transform = .identity
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment