0
0
iOS Swiftmobile~20 mins

Custom animation timing in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Custom Animation Timing
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What is the visible effect of this animation code?
Consider this Swift code snippet for a UIView animation with a custom timing curve. What will the user see when this animation runs?
iOS Swift
UIView.animate(withDuration: 2.0, delay: 0, options: [.curveEaseInOut], animations: {
  view.alpha = 0
}, completion: nil)
AThe view fades out instantly without any animation.
BThe view fades out at a constant speed over 2 seconds.
CThe view fades out quickly at first, then slows down towards the end.
DThe view fades out slowly at first, speeds up in the middle, then slows down before disappearing.
Attempts:
2 left
💡 Hint
Think about what the .curveEaseInOut option means for animation speed over time.
📝 Syntax
intermediate
2:00remaining
Which option correctly creates a custom timing curve animation?
You want to animate a view's position with a custom cubic timing curve. Which code snippet correctly uses UIViewPropertyAnimator with a custom timing curve?
A
let timing = UICubicTimingParameters(controlPoint1: CGPoint(x: 0.1, y: 0.9), controlPoint2: CGPoint(x: 0.2, y: 0.8))
let animator = UIViewPropertyAnimator(duration: 1.0, timingParameters: timing)
animator.addAnimations {
  view.frame.origin.x += 100
}
animator.startAnimation()
B
let animator = UIViewPropertyAnimator(duration: 1.0, timingParameters: UICubicTimingParameters(controlPoint1: CGPoint(x: 0.0, y: 0.0), controlPoint2: CGPoint(x: 1.0, y: 1.0)))
animator.addAnimations {
  view.frame.origin.x += 100
}
animator.startAnimation()
C
UIView.animate(withDuration: 1.0, delay: 0, options: [.curveLinear], animations: {
  view.frame.origin.x += 100
}, completion: nil)
D
let animator = UIViewPropertyAnimator(duration: 1.0, curve: .easeInOut) {
  view.frame.origin.x += 100
}
animator.startAnimation()
Attempts:
2 left
💡 Hint
Look for the option that uses UICubicTimingParameters with control points.
lifecycle
advanced
2:00remaining
What happens if you call startAnimation() twice on the same UIViewPropertyAnimator?
Given a UIViewPropertyAnimator instance, what is the effect of calling startAnimation() two times in a row without stopping or pausing?
iOS Swift
let animator = UIViewPropertyAnimator(duration: 1.0, curve: .easeInOut) {
  view.alpha = 0
}
animator.startAnimation()
animator.startAnimation()
AThe second call has no effect because the animation is already running.
BThe animation runs twice sequentially, fading out the view two times.
CThe animation restarts from the beginning on the second call.
DThe app crashes due to invalid animation state.
Attempts:
2 left
💡 Hint
Think about how UIViewPropertyAnimator manages its running state.
navigation
advanced
2:00remaining
How to synchronize a custom animation with a navigation controller transition?
You want to add a custom timing animation to a view during a UINavigationController push transition. Which approach correctly synchronizes your animation with the navigation transition?
AUse UIView.animate inside viewWillAppear of the pushed view controller without any coordination.
BStart your animation in viewDidLoad of the pushed view controller with a fixed delay matching the navigation animation duration.
CImplement UIViewControllerAnimatedTransitioning and use the transitionContext to run your custom animation synchronized with the navigation transition.
DAdd your animation in viewDidAppear of the pushed view controller after the navigation transition completes.
Attempts:
2 left
💡 Hint
Custom navigation animations require coordination with the transition system.
🔧 Debug
expert
2:00remaining
Why does this custom timing animation freeze halfway?
This code uses UIViewPropertyAnimator with a custom timing curve, but the animation freezes halfway and never completes. What is the most likely cause?
iOS Swift
let timing = UICubicTimingParameters(controlPoint1: CGPoint(x: 1.5, y: -0.5), controlPoint2: CGPoint(x: 0.5, y: 1.5))
let animator = UIViewPropertyAnimator(duration: 2.0, timingParameters: timing)
animator.addAnimations {
  view.alpha = 0
}
animator.startAnimation()
AThe view's alpha property cannot be animated with a custom timing curve.
BThe control points are outside the valid range, causing the animation to behave unpredictably and freeze.
CThe animation duration is too long, causing it to appear frozen.
DThe animator was not retained and got deallocated immediately.
Attempts:
2 left
💡 Hint
Check the valid range for cubic Bezier control points in timing curves.