Bird
0
0

What will be the visible effect when running this Swift code snippet?

medium📝 ui behavior Q13 of 15
iOS Swift - Animations
What will be the visible effect when running this Swift code snippet?
let transition = CATransition()
transition.type = "push"
transition.subtype = "fromRight"
view.layer.add(transition, forKey: "transition")
view.backgroundColor = .red
AThe view background color changes instantly with no animation
BThe view background color changes with a push animation from the right
CThe view background color fades in smoothly
DThe app crashes due to invalid transition subtype
Step-by-Step Solution
Solution:
  1. Step 1: Analyze transition type and subtype

    The transition type is "push" and subtype is "fromRight", meaning the new content will push in from the right side.
  2. Step 2: Understand effect on view background color

    Adding the transition to the layer and then changing backgroundColor triggers the push animation showing the color change.
  3. Final Answer:

    The view background color changes with a push animation from the right -> Option B
  4. Quick Check:

    Push + fromRight = push animation from right [OK]
Quick Trick: Push + fromRight means slide in from right [OK]
Common Mistakes:
  • Expecting fade instead of push animation
  • Thinking background changes instantly without animation
  • Assuming invalid subtype causes crash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes