Bird
0
0

Consider this SwiftUI code:

medium📝 Predict Output Q5 of 15
iOS Swift - Animations
Consider this SwiftUI code:
Circle()
  .frame(width: 100, height: 100)
  .scaleEffect(isScaled ? 1.5 : 1)
  .animation(.spring(), value: isScaled)
  .onTapGesture { isScaled.toggle() }
What is the visual effect when the circle is tapped?
AThe circle changes color with no size change
BThe circle rotates 360 degrees
CThe circle instantly scales without animation
DThe circle grows and shrinks with a spring bounce animation
Step-by-Step Solution
Solution:
  1. Step 1: Identify the scaleEffect change

    The circle scales between 1 and 1.5 depending on isScaled state.
  2. Step 2: Understand the spring animation

    The .animation(.spring(), value: isScaled) applies a spring bounce effect to the scaling change.
  3. Final Answer:

    The circle grows and shrinks with a spring bounce animation -> Option D
  4. Quick Check:

    Spring animation = bounce scale effect [OK]
Quick Trick: Use .animation(.spring()) for bouncy implicit animations [OK]
Common Mistakes:
  • Expecting color change
  • Missing animation on scale
  • Confusing rotation with scale

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes