Search Docs
Loading...
Skip to content

Edit Animations

Modify existing animations by reading properties, changing duration and easing, and replacing or removing animations from blocks.

5 mins
estimated time
GitHub

Editing animations in CE.SDK involves retrieving existing animations from blocks and modifying their properties. This guide assumes you’ve already created and attached animations to blocks as covered in the Base Animations guide.

This guide covers retrieving animations, reading and modifying properties, changing easing functions, adjusting animation-specific settings, and replacing or removing animations.

Retrieving Animations#

Before modifying an animation, retrieve it from the block using getInAnimation, getOutAnimation, or getLoopAnimation. We use getType to identify the animation type.

let inAnimation = try engine.block.getInAnimation(block)
let outAnimation = try engine.block.getOutAnimation(block)
let loopAnimation = try engine.block.getLoopAnimation(block)
let inType = try engine.block.getType(inAnimation)
let outType = try engine.block.getType(outAnimation)

Reading Animation Properties#

Inspect current animation settings using property getters. getDuration returns the animation length in seconds, while getEnum retrieves values like easing functions. Use findAllProperties to discover all configurable properties for an animation.

let currentDuration = try engine.block.getDuration(inAnimation)
let currentEasing = try engine.block.getEnum(inAnimation, property: "animationEasing")
let allProperties = try engine.block.findAllProperties(inAnimation)

Different animation types expose different properties — slide animations have direction, while loop animations may have intensity or scale properties.

Modifying Animation Duration#

Change animation timing with setDuration. The duration is specified in seconds.

try engine.block.setDuration(inAnimation, duration: 0.8)
try engine.block.setDuration(loopAnimation, duration: 2.0)

When modifying In or Out animation durations, CE.SDK automatically adjusts the paired animation to prevent overlap. For loop animations, the duration defines the cycle length.

Changing Easing Functions#

Easing controls animation acceleration. We use setEnum with the "animationEasing" property to change it.

try engine.block.setEnum(inAnimation, property: "animationEasing", value: "EaseOut")
let easingOptions = try engine.block.getEnumValues(ofProperty: "animationEasing")

Use getEnumValues(ofProperty: "animationEasing") to discover available options:

EasingDescription
LinearConstant speed throughout
EaseInStarts slow, accelerates toward the end
EaseOutStarts fast, decelerates toward the end
EaseInOutStarts slow, speeds up, then slows down again

Adjusting Animation-Specific Properties#

Each animation type has unique configurable properties. For slide animations, we can change the entry direction using setFloat.

try engine.block.setFloat(
inAnimation,
property: "animation/slide/direction",
value: .pi,
)
let direction = try engine.block.getFloat(inAnimation, property: "animation/slide/direction")

For a full list of direction values and other animation-specific properties, see Supported Animation Types.

Replacing Animations#

To swap an animation type, destroy the existing animation before setting a new one. This prevents memory leaks from orphaned animation objects.

let currentIn = try engine.block.getInAnimation(block)
try engine.block.destroy(currentIn)
let zoomAnimation = try engine.block.createAnimation(.zoom)
try engine.block.setInAnimation(block, animation: zoomAnimation)
try engine.block.setDuration(zoomAnimation, duration: 0.6)
try engine.block.setEnum(zoomAnimation, property: "animationEasing", value: "EaseInOut")

Removing Animations#

Remove an animation by destroying it with destroy.

let currentLoop = try engine.block.getLoopAnimation(block)
try engine.block.destroy(currentLoop)
// Destroying a design block also destroys all its attached animations
// try engine.block.destroy(block)

Destroying a design block automatically destroys all its attached animations. However, detached animations must be destroyed manually to free memory.

API Reference#

MethodDescription
engine.block.getInAnimation(block)Get entrance animation ID
engine.block.getOutAnimation(block)Get exit animation ID
engine.block.getLoopAnimation(block)Get loop animation ID
engine.block.getType(anim)Get animation type string
engine.block.getDuration(anim)Get animation duration in seconds
engine.block.setDuration(anim, duration:)Set animation duration
engine.block.getEnum(anim, property:)Get enum property value
engine.block.setEnum(anim, property:, value:)Set enum property value
engine.block.getFloat(anim, property:)Get float property value
engine.block.setFloat(anim, property:, value:)Set float property value
engine.block.findAllProperties(anim)Get all available properties
engine.block.getEnumValues(ofProperty:)Get available values for enum property
engine.block.destroy(anim)Destroy animation and free memory

Next Steps#