CABasicAnimationBuilder

Struct CABasicAnimationBuilder 

Source
pub struct CABasicAnimationBuilder { /* private fields */ }
Expand description

Builder for configuring CABasicAnimation instances.

Creates from→to animations on a single property. The builder uses sensible defaults:

  • fillMode = forwards (values persist after animation)
  • removedOnCompletion = false (animation stays attached)
  • easing = InOut (smooth acceleration/deceleration)
  • repeat = Once (play once)

§Examples

// Simple pulse animation
let anim = CABasicAnimationBuilder::new(KeyPath::TransformScale)
    .values(0.85, 1.15)
    .duration(800.millis())
    .autoreverses()
    .repeat(Repeat::Forever)
    .build();

layer.addAnimation_forKey(&anim, Some(ns_string!("pulse")));

§Default Behaviors

By default, the animation’s final value persists on the layer after completion. This differs from raw CABasicAnimation which snaps back to the original value. Call .remove_on_completion() to opt-in to snap-back behavior.

Implementations§

Source§

impl CABasicAnimationBuilder

Source

pub fn new(key_path: KeyPath) -> Self

Creates a new animation builder for the specified property.

§Arguments
  • key_path - The property to animate (e.g., KeyPath::TransformScale)
§Examples
let builder = CABasicAnimationBuilder::new(KeyPath::Opacity);
Source

pub fn values(self, from: f64, to: f64) -> Self

Sets the from and to values for the animation.

The values are interpreted based on the key path:

  • Scale properties: 0.0 = invisible, 1.0 = normal
  • Opacity: 0.0 = transparent, 1.0 = opaque
  • Rotation: radians
  • Position: points
§Arguments
  • from - Starting value
  • to - Ending value
§Examples
// Scale from 85% to 115%
builder.values(0.85, 1.15)

// Fade from fully opaque to 70% opacity
builder.values(1.0, 0.7)
Source

pub fn duration(self, duration: Duration) -> Self

Sets the duration of one animation cycle.

§Arguments
  • duration - The time for one complete animation cycle
§Examples
use std::time::Duration;

builder.duration(Duration::from_millis(800))

// Or with DurationExt:
builder.duration(800.millis())
builder.duration(1.5.seconds())
Source

pub fn easing(self, easing: Easing) -> Self

Sets the easing curve for the animation.

The default is Easing::InOut which provides smooth acceleration at the start and deceleration at the end.

§Arguments
  • easing - The timing curve to use
§Examples
// Constant speed
builder.easing(Easing::Linear)

// Quick start, slow end
builder.easing(Easing::Out)
Source

pub fn autoreverses(self) -> Self

Enables ping-pong animation (play forward then backward).

When combined with repeat(Repeat::Forever), creates a smooth oscillating animation.

§Examples
// Pulse that smoothly grows and shrinks
builder
    .values(0.9, 1.1)
    .autoreverses()
    .repeat(Repeat::Forever)
Source

pub fn repeat(self, repeat: Repeat) -> Self

Sets the repeat behavior for the animation.

§Arguments
  • repeat - How many times to play the animation
§Examples
// Play 3 times
builder.repeat(Repeat::Times(3))

// Loop forever
builder.repeat(Repeat::Forever)
Source

pub fn phase_offset(self, offset: f64) -> Self

Sets the phase offset (starting point within the animation cycle).

This allows multiple animations to be out of phase with each other, creating interesting visual effects.

§Arguments
  • offset - Fraction of the cycle to skip (0.0 to 1.0).
    • 0.0 = start at beginning (default)
    • 0.5 = start at midpoint
    • 1.0 = start at end (same as beginning for looping animations)
§Examples
// Two circles pulsing out of phase
let anim1 = builder.clone().phase_offset(0.0).build();
let anim2 = builder.clone().phase_offset(0.5).build();
Source

pub fn remove_on_completion(self) -> Self

Opts in to snap-back behavior (remove animation on completion).

By default, the animation’s final value persists on the layer. Calling this method causes the layer to snap back to its original value when the animation completes.

§Examples
// Animation snaps back to original value when done
builder
    .values(0.0, 1.0)
    .repeat(Repeat::Times(3))
    .remove_on_completion()
Source

pub fn build(self) -> Retained<CABasicAnimation>

Builds and returns the configured CABasicAnimation.

§Returns

A retained CABasicAnimation ready to be added to a layer.

§Examples
let anim = CABasicAnimationBuilder::new(KeyPath::TransformScale)
    .values(0.85, 1.15)
    .duration(800.millis())
    .autoreverses()
    .repeat(Repeat::Forever)
    .build();

layer.addAnimation_forKey(&anim, Some(ns_string!("pulse")));

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,