Bird
0
0

Which code snippet correctly sets up this transition effect before presenting the new view controller?

hard📝 navigation Q15 of 15
iOS Swift - Animations
You want to create a custom transition that slides a new view controller from the bottom with a duration of 0.5 seconds. Which code snippet correctly sets up this transition effect before presenting the new view controller?
Alet transition = CATransition() transition.duration = 0.5 transition.type = "push" transition.subtype = "fromBottom" view.window?.layer.add(transition, forKey: "transition") present(newVC, animated: false)
Blet transition = CATransition() transition.duration = 0.5 transition.type = "fade" transition.subtype = "fromBottom" view.layer.add(transition, forKey: nil) present(newVC, animated: true)
Clet transition = CATransition() transition.duration = 0.5 transition.type = "moveIn" transition.subtype = "fromTop" view.window?.layer.add(transition, forKey: "slide") present(newVC, animated: true)
Dlet transition = CATransition() transition.duration = 0.5 transition.type = "push" transition.subtype = "fromBottom" view.layer.add(transition, forKey: "transition") present(newVC, animated: true)
Step-by-Step Solution
Solution:
  1. Step 1: Choose correct transition type and subtype

    To slide from bottom, use "push" type with "fromBottom" subtype.
  2. Step 2: Add transition to window layer and disable default animation

    Adding to view.window?.layer ensures whole screen transition. Presenting with animated: false disables default animation so custom one shows.
  3. Final Answer:

    Use "push" fromBottom on window layer and present with animated false -> Option A
  4. Quick Check:

    Custom slide from bottom = "push" + "fromBottom" + animated false [OK]
Quick Trick: Add transition to window layer and present with animated false [OK]
Common Mistakes:
  • Adding transition to view.layer instead of window.layer
  • Using animated: true which overrides custom animation
  • Using wrong transition type or subtype

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes