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
impl CABasicAnimationBuilder
Sourcepub fn values(self, from: f64, to: f64) -> Self
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 valueto- 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)Sourcepub fn easing(self, easing: Easing) -> Self
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)Sourcepub fn autoreverses(self) -> Self
pub fn autoreverses(self) -> Self
Sourcepub fn phase_offset(self, offset: f64) -> Self
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();Sourcepub fn remove_on_completion(self) -> Self
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()Sourcepub fn build(self) -> Retained<CABasicAnimation> ⓘ
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")));