Challenge - 5 Problems
Transition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the visible effect of this transition code?
Consider this Swift code snippet for a view controller transition. What visual effect will the user see when this transition runs?
iOS Swift
let transition = CATransition() transition.duration = 0.5 transition.type = CATransitionType.push transition.subtype = CATransitionSubtype.fromRight view.window?.layer.add(transition, forKey: nil) navigationController?.popViewController(animated: false)
Attempts:
2 left
💡 Hint
Look at the transition type and subtype properties to understand the direction and style.
✗ Incorrect
The CATransition with type 'push' and subtype 'fromRight' causes the new view to slide in from the right side, pushing the old view out.
❓ lifecycle
intermediate2:00remaining
When does the transition animation start in this code?
Given this code snippet inside a UIViewController, at what point does the transition animation begin?
iOS Swift
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
let transition = CATransition()
transition.duration = 0.3
transition.type = CATransitionType.fade
view.window?.layer.add(transition, forKey: nil)
}Attempts:
2 left
💡 Hint
Check which lifecycle method is overridden and when it is called.
✗ Incorrect
The viewWillDisappear method is called just before the view disappears, so the transition animation starts then.
📝 Syntax
advanced2:00remaining
What error does this transition code produce?
Analyze this Swift code snippet for a transition. What error will it cause when compiled?
iOS Swift
let transition = CATransition() transition.duration = 0.4 transition.type = "slide" view.window?.layer.add(transition, forKey: nil)
Attempts:
2 left
💡 Hint
Check the type of the 'type' property and what values it accepts.
✗ Incorrect
There is a compile-time error because the 'type' property expects a CATransitionType, not a String. "slide" is not a valid CATransitionType.
advanced
2:00remaining
Which option correctly adds a custom transition when pushing a new view controller?
You want to push a new view controller with a fade transition. Which code snippet correctly achieves this?
Attempts:
2 left
💡 Hint
The transition must be added to the navigation controller's view layer before pushing without animation.
✗ Incorrect
Adding the transition to navigationController?.view.layer before pushing with animated: false triggers the custom animation correctly.
🧠 Conceptual
expert2:00remaining
Why might a custom CATransition not appear when pushing a view controller?
You added a CATransition to the window's layer before pushing a view controller, but the animation does not show. What is the most likely reason?
Attempts:
2 left
💡 Hint
Check the animated parameter in the navigation call.
✗ Incorrect
If animated: true is used, the default navigation animation overrides the custom CATransition animation.