Skip to content

Instantly share code, notes, and snippets.

@romanmiller
Last active March 18, 2017 10:04
Show Gist options
  • Save romanmiller/ceaa691805203efcfc01b5220071851f to your computer and use it in GitHub Desktop.
Save romanmiller/ceaa691805203efcfc01b5220071851f to your computer and use it in GitHub Desktop.
Spring animation for UIButton (can use in extension for UIButton or for your custom button class) (Swift)
// from: size that button start animated; duration: time for animation;
func animateSpring(from: CGFloat,duration: TimeInterval) {
let scale = from / self.bounds.height
self.transform = CGAffineTransform(scaleX: scale, y: scale)
UIView.animate(withDuration: duration,
delay: 0,
usingSpringWithDamping: 0.6,
initialSpringVelocity: 0.4,
options: .allowUserInteraction,
animations: { [weak self] in
self?.transform = .identity
}, completion: nil)
}
@andymedvedev
Copy link

Пожалуйста, расскажи что означает параметр "usingSpingWithDaming"?

@romanmiller
Copy link
Author

"usingSpingWithDamping" це сила амортизації або прижка обєкта тобто в випадку коли ти робиш анімацію з scale від меншого до більшого розміру Damping буде наднормово збільшувати твій розмір обєкту (більше ніж задана) і верне його в заданий розмір.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment