Challenge - 5 Problems
Spring Animation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediateWhat is the visible effect of this spring animation code?
Consider this Swift code snippet for a UIView animation using spring damping. What will the user see when this code runs?
iOS Swift
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.5, options: [], animations: { view.frame.origin.y += 100 }, completion: nil)
Attempts:
2 left
💡 Hint
Lower damping values cause more bounce in spring animations.
✗ Incorrect
A low damping value like 0.3 causes the animation to overshoot and bounce multiple times before settling. The initial velocity affects how fast it starts moving.
📝 Syntax
intermediateWhich option correctly uses spring animation with completion handler?
Select the Swift code snippet that correctly performs a spring animation on a view's alpha property and runs a completion block after animation.
Attempts:
2 left
💡 Hint
Check the method signature for spring animations with completion.
✗ Incorrect
Option C uses the correct method signature including delay, damping, velocity, options, animations, and completion handler.
❓ lifecycle
advancedWhat happens if you start a spring animation on a view that is not yet in the view hierarchy?
You create a UIView and start a spring animation on it before adding it to the visible view hierarchy. What is the expected behavior?
Attempts:
2 left
💡 Hint
Animations require the view to be in the window to be visible.
✗ Incorrect
Animations on views not in the hierarchy do not run. When the view is added, it appears immediately at the final state without animation.
advanced
How to chain two spring animations so the second starts after the first completes?
You want to animate a view moving right with a spring animation, then after it finishes, animate it moving down with another spring animation. Which code snippet achieves this chaining correctly?
Attempts:
2 left
💡 Hint
Use the completion block of the first animation to start the second.
✗ Incorrect
Option A correctly starts the second animation inside the completion block of the first, ensuring sequential execution without extra delay.
🔧 Debug
expertWhy does this spring animation not bounce as expected?
This code is intended to animate a view with a spring effect that bounces, but it moves smoothly without bounce. What is the cause?
iOS Swift
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [], animations: { view.transform = CGAffineTransform(scaleX: 1.5, y: 1.5) }, completion: nil)
Attempts:
2 left
💡 Hint
Damping controls how much the animation oscillates.
✗ Incorrect
A damping value of 1.0 means no oscillation; the animation smoothly reaches the final state without bouncing.
