Bird
0
0

Identify the error in this spring animation code:

medium📝 Debug Q14 of 15
iOS Swift - Animations
Identify the error in this spring animation code:
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: -0.5, initialSpringVelocity: 0.5, options: [], animations: {
    view.alpha = 0
}, completion: nil)
AinitialSpringVelocity must be zero
BAlpha cannot be animated
CDuration cannot be 1.0 seconds
DusingSpringWithDamping cannot be less than 0
Step-by-Step Solution
Solution:
  1. Step 1: Check dampingRatio valid range

    The usingSpringWithDamping parameter must be greater than or equal to 0.
  2. Step 2: Identify invalid value

    Here, -0.5 is invalid and will cause the animation to diverge or behave incorrectly.
  3. Final Answer:

    usingSpringWithDamping cannot be less than 0 -> Option D
  4. Quick Check:

    dampingRatio >= 0 [OK]
Quick Trick: Damping ratio must be >= 0 [OK]
Common Mistakes:
  • Setting dampingRatio below 0
  • Thinking initialSpringVelocity must be zero
  • Believing alpha cannot be animated

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes