A. The transition key should not be nil; use a string key instead
B. The transition type "moveIn" is invalid
C. The transition must be added before changing the background color
D. Using nil for the key causes the transition not to work
Solution
Step 1: Check the add method parameters
The add method requires a non-nil string key to identify the animation. Passing nil disables the animation.
Step 2: Confirm transition type validity
"moveIn" is a valid transition type, so no error there.
Final Answer:
The transition key should not be nil; use a string key instead -> Option A
Quick Check:
Animation key must be non-nil string [OK]
Hint: Always provide a string key when adding animations [OK]
Common Mistakes:
Passing nil key disables animation silently
Confusing transition type validity
Thinking order of adding transition matters
5. 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?
hard
A. let transition = CATransition()
transition.duration = 0.5
transition.type = "push"
transition.subtype = "fromBottom"
view.window?.layer.add(transition, forKey: "transition")
present(newVC, animated: false)
B. let transition = CATransition()
transition.duration = 0.5
transition.type = "fade"
transition.subtype = "fromBottom"
view.layer.add(transition, forKey: nil)
present(newVC, animated: true)
C. let transition = CATransition()
transition.duration = 0.5
transition.type = "moveIn"
transition.subtype = "fromTop"
view.window?.layer.add(transition, forKey: "slide")
present(newVC, animated: true)
D. let transition = CATransition()
transition.duration = 0.5
transition.type = "push"
transition.subtype = "fromBottom"
view.layer.add(transition, forKey: "transition")
present(newVC, animated: true)
Solution
Step 1: Choose correct transition type and subtype
To slide from bottom, use "push" type with "fromBottom" subtype.
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.
Final Answer:
Use "push" fromBottom on window layer and present with animated false -> Option A