Component - Spring animations
This UI component demonstrates a spring animation in iOS using Swift. When the user taps the button, a square view moves horizontally with a bouncing effect, mimicking a spring motion.
This UI component demonstrates a spring animation in iOS using Swift. When the user taps the button, a square view moves horizontally with a bouncing effect, mimicking a spring motion.
UIViewController ├── UIView (main view) │ ├── UIView (animated square) │ └── UIButton (trigger animation)
dampingRatio parameter control in a spring animation?dampingRatio controls the amount of oscillation or bounce in the animation.UIView.animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:).UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0, options: [], animations: {
view.frame.origin.y += 100
}, completion: nil)UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: -0.5, initialSpringVelocity: 0.5, options: [], animations: {
view.alpha = 0
}, completion: nil)usingSpringWithDamping parameter must be greater than or equal to 0.Pass the test and this pattern moves unknown