Methods

DotLottieAnimation instances expose the following methods that can be used to control the animation:

MethodDescription
play()Begins playback from the current animation position.
play(fromFrame: Float)Begins playback from a specific animation frame.
play(fromProgress: Float)Begins playback from a specific animation progress (0…1).
pause()Pauses the animation without resetting its position.
stop()Halts playback and returns the animation to its initial frame.
setSpeed(speed: Float)Sets the playback speed with the given multiplier.
setLoop(loop: Bool)Configures whether the animation should loop continuously.
setFrame(frame: Float)Directly navigates the animation to a specified frame.
setProgress(progress: Float)Directly navigates the animation to a specified progress (0…1).
loadAnimationById(_ animationId: String)Loads the animation by id. Animation id’s are visible inside the manifest, recoverable via the manifest() method.
setMode(mode: Mode)Sets the animation play mode.
setSegments(segments: (Float, Float))Sets the start and end frame of the animation.
setBackgroundColor(bgColor: CIImage)Sets the background color of the animation.
setFrameInterpolation(_ useFrameInterpolation: Bool)Uses frame interpolation or not.
resize(width: Int, height: Int)Manually resizes the animation.
setTheme(_ themeId: String)Loads a theme. Only available with .lottie files.
setThemeData(_ themeData: String)Loads the passed theming data.
resetTheme()Removes the currently loaded theme. Only available with .lottie files.
setMarker(marker: String)Sets a marker for the animation timeline.
setAutoplay(autoplay: Bool)Sets whether the animation should autoplay.
setSlots(_ slots: String)Sets slots for the animation (theme/text replacement).
getLayerBounds(layerName: String) -> [Float]Returns the bounds of a specific layer.
tick() -> CGImage?Requests a frame and renders it if necessary. Returns the current frame as CGImage.
frameImage() -> CGImage?Generates and returns the current frame image as CGImage.
render() -> BoolRenders the current frame. Returns true if rendering was successful.

State Machine Methods

MethodDescription
stateMachineLoad(id: String)Loads a state machine by ID.
stateMachineLoadData(_ data: String)Loads state machine data.
stateMachineStart(openUrlPolicy:)Starts the state machine with URL policy.
stateMachineStop()Stops the state machine.
stateMachinePostEvent(_ event: Event, force: Bool?)Posts an event to the state machine.
stateMachineSubscribe(_ observer: StateMachineObserver)Subscribe to state machine events.
stateMachineUnSubscribe(observer: StateMachineObserver)Unsubscribe from state machine events.
stateMachineSetNumericInput(key: String, value: Float)Set numeric input for state machine.
stateMachineSetStringInput(key: String, value: String)Set string input for state machine.
stateMachineSetBooleanInput(key: String, value: Bool)Set boolean input for state machine.
stateMachineCurrentState()Returns the current state machine state.

Advanced Methods

MethodDescription
subscribe(observer: Observer)Subscribe to animation lifecycle events.
unsubscribe(observer: Observer)Unsubscribe from animation lifecycle events.