<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAAnimationDelegate",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(pl)CAAnimationDelegate"
  },
  "title" : "CAAnimationDelegate"
}
-->

# CAAnimationDelegate

Methods your app can implement to respond when animations start and stop.

```
protocol CAAnimationDelegate : NSObjectProtocol
```

## Overview

You can use an animation delegate to execute additional logic when an animation starts or ends. For example, you may want to remove a layer from its parent once a fade out animation has completed.

The following example shows code taken from a class that implements [`CAAnimationDelegate`](/documentation/QuartzCore/CAAnimationDelegate) and has had a layer, named `sublayer`, added to its layer. The `fadeOut` function animates the opacity of `sublayer` and, once the animation has completed, [`animationDidStop(_:finished:)`](/documentation/QuartzCore/CAAnimationDelegate/animationDidStop(_:finished:)) removes it from its superlayer.

```swift
func fadeOut() {
    let fadeOutAnimation = CABasicAnimation()
    fadeOutAnimation.keyPath = "opacity"
    fadeOutAnimation.fromValue = 1
    fadeOutAnimation.toValue = 0
    fadeOutAnimation.duration = 0.25
    
    fadeOutAnimation.delegate = self
    
    sublayer.add(fadeOutAnimation,
                      forKey: "fade")
}
    
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
    sublayer.removeFromSuperlayer()
}
```

## Topics

### Customizing Start and Stop Times

[`animationDidStart(_:)`](/documentation/QuartzCore/CAAnimationDelegate/animationDidStart(_:))

Tells the delegate the animation has started.

[`animationDidStop(_:finished:)`](/documentation/QuartzCore/CAAnimationDelegate/animationDidStop(_:finished:))

Tells the delegate the animation has ended.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)