Bird
0
0

Identify the error in this Core Animation timing code:

medium📝 Debug Q14 of 15
iOS Swift - Animations
Identify the error in this Core Animation timing code:
let animation = CABasicAnimation(keyPath: "opacity")
animation.duration = 1.0
animation.timingFunction = CAMediaTimingFunction(name: .easeIn)
animation.fromValue = 1.0
animation.toValue = 0.0
view.layer.add(animation, forKey: "fade")
AThe animation is missing a fillMode to keep final state.
BThe timingFunction property expects a string, not CAMediaTimingFunction.
CThe keyPath "opacity" is invalid for CABasicAnimation.
DThe timing function name should be .easeInEaseOut, not .easeIn.
Step-by-Step Solution
Solution:
  1. Step 1: Check timingFunction usage

    Using CAMediaTimingFunction(name: .easeIn) is correct and supported.
  2. Step 2: Identify missing fillMode

    Without setting fillMode and isRemovedOnCompletion, the animation resets after finishing, so the view returns to original opacity.
  3. Final Answer:

    The animation is missing a fillMode to keep final state. -> Option A
  4. Quick Check:

    Missing fillMode causes animation to revert [OK]
Quick Trick: Add fillMode and isRemovedOnCompletion to keep final state [OK]
Common Mistakes:
  • Assuming .easeIn is invalid timing function name
  • Thinking timingFunction needs a string
  • Ignoring fillMode and completion behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes