Complete the code to create a spring animation with UIView.animate.
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: [1], initialSpringVelocity: 0.5, options: [], animations: { view.alpha = 1.0 }, completion: nil)
The usingSpringWithDamping parameter controls the bounciness of the animation. Values between 0 and 1 create a spring effect. 0.5 is a common choice for a smooth spring.
Complete the code to set the initial velocity for a spring animation.
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: [1], options: [], animations: { view.frame.origin.y += 100 }, completion: nil)
The initialSpringVelocity parameter defines the starting speed of the animation. A value of 1.0 means the animation starts at the natural speed of the change.
Fix the error in the spring animation code by completing the missing option.
UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.8, options: [1], animations: { view.transform = CGAffineTransform(scaleX: 1.2, y: 1.2) }, completion: nil)
The options parameter expects UIView.AnimationOptions. .curveEaseInOut is a common choice for smooth animation timing.
Fill both blanks to create a spring animation with a delay and completion handler.
UIView.animate(withDuration: 1.2, delay: [1], usingSpringWithDamping: 0.7, initialSpringVelocity: 1.0, options: [], animations: { view.alpha = 0 }, completion: [2])
The delay parameter sets how long to wait before starting the animation. The completion handler runs code after the animation finishes.
Fill all three blanks to create a spring animation that moves a view and resets its transform after completion.
UIView.animate(withDuration: [1], delay: 0, usingSpringWithDamping: [2], initialSpringVelocity: 0.9, options: [], animations: { view.center.x += 150 }, completion: [3])
Duration controls how long the animation lasts. Damping controls the spring effect. The completion closure resets the view's transform to normal.