Implicit and Explicit Animations
Animate layer properties with CABasicAnimation.
Implicit and Explicit Animations is a free Swift Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Ways to Animate Layers
Core Animation offers implicit animations (automatic on property change) and explicit animations (you create an animation object).
Knowing both, and how they interact, is key to smooth motion.
Implicit Animations
Changing an animatable property of a standalone layer triggers an implicit animation using a default 0.25s curve—no animation object required.
let layer = CALayer()
// Later, this animates automatically:
layer.opacity = 0.0Animatable Properties
Many layer properties are animatable: opacity, position, bounds, backgroundColor, transform, cornerRadius, and more.
layer.cornerRadius = 20 // animates implicitly
layer.backgroundColor = UIColor.systemGreen.cgColorActions and the Action Mechanism
Implicit animations are driven by actions. When a property changes, the layer looks up a CAAction to run. You can customize or disable these actions.
View-Backed Layers Disable Implicit
Layers attached to a UIView have implicit animations turned off. You animate them through UIView.animate instead, or with explicit animations.
UIView.animate(withDuration: 0.3) {
view.alpha = 0
}CABasicAnimation
CABasicAnimation animates one property between a fromValue and toValue. Add it to the layer with a key path matching the property.
let anim = CABasicAnimation(keyPath: "opacity")
anim.fromValue = 1.0
anim.toValue = 0.0
anim.duration = 0.5
layer.add(anim, forKey: "fade")Presentation vs Model
An explicit animation changes only the presentation (on-screen) values; the layer’s model value snaps back when the animation ends.
To make the change stick, set the model value too.
layer.opacity = 0.0 // set model value so it persists
layer.add(anim, forKey: "fade")Keyframe Animations
CAKeyframeAnimation animates through multiple values over keyTimes, or along a path—ideal for bounces or motion along curves.
let move = CAKeyframeAnimation(keyPath: "position")
move.values = [
NSValue(cgPoint: CGPoint(x: 0, y: 0)),
NSValue(cgPoint: CGPoint(x: 100, y: 0)),
NSValue(cgPoint: CGPoint(x: 100, y: 100))
]
move.duration = 1.0
layer.add(move, forKey: "path")Timing Functions
Control acceleration with timingFunction: ease-in, ease-out, linear, or a custom cubic Bezier.
anim.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)Grouping and Transactions
Wrap multiple changes in a CATransaction to share duration and timing, or to disable implicit animations entirely.
CATransaction.begin()
CATransaction.setDisableActions(true)
layer.position = CGPoint(x: 200, y: 200)
CATransaction.commit()Animation Delegates and Completion
Set CATransaction.setCompletionBlock or an animation delegate to run code when motion finishes—cleanup, chaining, or state updates.
CATransaction.begin()
CATransaction.setCompletionBlock { print("done") }
layer.add(anim, forKey: "fade")
CATransaction.commit()Quick Check: Animations
Test your understanding of implicit vs explicit animations.
Recap: Implicit and Explicit Animations
Standalone layers animate implicitly via actions on animatable property changes; view-backed layers disable this and use UIView.animate. Explicit CABasicAnimation and CAKeyframeAnimation animate the presentation value, so update the model value to persist results.
Tune motion with timing functions, batch changes in CATransaction, and use completion blocks for follow-up work.
Frequently asked questions
Is the “Implicit and Explicit Animations” lesson free?
Yes — the full text of “Implicit and Explicit Animations” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.
What will I learn in “Implicit and Explicit Animations”?
Animate layer properties with CABasicAnimation. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Implicit and Explicit Animations” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- CALayer Fundamentals
- Implicit and Explicit Animations
- Transforms and 3D Effects
- Custom Drawing with Core Graphics