Swift Academy · Lesson

Implicit and Explicit Animations

Animate layer properties with CABasicAnimation.

Lesson 2 of 413 steps

Implicit and Explicit Animations is a free Swift Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.

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.0

Animatable Properties

Many layer properties are animatable: opacity, position, bounds, backgroundColor, transform, cornerRadius, and more.

layer.cornerRadius = 20 // animates implicitly
layer.backgroundColor = UIColor.systemGreen.cgColor

Actions 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.

Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “Implicit and Explicit Animations” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “Implicit and Explicit Animations”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

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

  1. CALayer Fundamentals
  2. Implicit and Explicit Animations
  3. Transforms and 3D Effects
  4. Custom Drawing with Core Graphics
← Back to Swift Academy