0
0
iOS Swiftmobile~10 mins

Spring animations in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a spring animation with UIView.animate.

iOS Swift
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: [1], initialSpringVelocity: 0.5, options: [], animations: {
    view.alpha = 1.0
}, completion: nil)
Drag options to blanks, or click blank then click option'
A0
B1.5
C2.0
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a damping value greater than 1 causes no spring effect.
Using 0 causes infinite bouncing.
2fill in blank
medium

Complete the code to set the initial velocity for a spring animation.

iOS Swift
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: [1], options: [], animations: {
    view.frame.origin.y += 100
}, completion: nil)
Drag options to blanks, or click blank then click option'
A5.0
B1.0
C0
D-1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero velocity causes the animation to start slowly.
Negative velocity causes runtime errors.
3fill in blank
hard

Fix the error in the spring animation code by completing the missing option.

iOS Swift
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)
Drag options to blanks, or click blank then click option'
A.allowUserInteraction
B.repeat
C.curveEaseInOut
D.autoreverse
Attempts:
3 left
💡 Hint
Common Mistakes
Using .repeat causes the animation to loop infinitely.
Using .autoreverse causes the animation to reverse automatically.
4fill in blank
hard

Fill both blanks to create a spring animation with a delay and completion handler.

iOS Swift
UIView.animate(withDuration: 1.2, delay: [1], usingSpringWithDamping: 0.7, initialSpringVelocity: 1.0, options: [], animations: {
    view.alpha = 0
}, completion: [2])
Drag options to blanks, or click blank then click option'
A0.3
Bnil
C{ _ in print("Animation done") }
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Passing nil for delay causes no delay.
Passing true for completion causes a type error.
5fill in blank
hard

Fill all three blanks to create a spring animation that moves a view and resets its transform after completion.

iOS Swift
UIView.animate(withDuration: [1], delay: 0, usingSpringWithDamping: [2], initialSpringVelocity: 0.9, options: [], animations: {
    view.center.x += 150
}, completion: [3])
Drag options to blanks, or click blank then click option'
A1.0
B0.5
C{ _ in view.transform = .identity }
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Using nil for completion when a closure is needed.
Using damping greater than 1 removes spring effect.