Projection
project(value:velocity:decelerationRate:)
Projects a scalar value based on its velocity, simulating where the value would end up after natural deceleration.The current value
The current velocity (points per second)
The deceleration rate (0-1). Higher values = slower deceleration
project(point:velocity:decelerationRate:)
Projects a 2D point based on its 2D velocity.The current point
The current velocity (points per second in x and y)
The deceleration rate (0-1)
Projection is commonly used to determine snap targets in gesture-driven animations. When a user releases a dragged object, you can project where it would naturally end up and snap to the nearest valid position.
Value mapping
mapRange(value:inMin:inMax:outMin:outMax:clip:)
Maps a value from one range to another using linear interpolation.The value to map
The minimum of the input range
The maximum of the input range
The minimum of the output range
The maximum of the output range
If true, clamps the result to the output range
mapRange(::::_:clip:)
Convenience overload that omits parameter labels for more concise syntax.Boundary functions
clip(value:lower:upper:)
Clamps a value to a specified range.The value to clamp
The minimum allowed value (inclusive)
The maximum allowed value (inclusive)
clipUnit(value:)
Clamps a value to the range [0, 1].The value to clamp
Rubber-banding
rubberband(value:range:interval:c:)
Applies a rubber-band effect to values outside a specified range, similar to UIScrollView’s overscroll behavior.The input value
The range within which no rubber-banding occurs
The dimension used for rubber-band calculations (e.g., view width or height)
The rubber-band constant. UIScrollView uses 0.55. Lower values = stronger resistance
Values within the specified range are returned unchanged. Values outside the range are progressively compressed using the rubber-band formula, creating a resistance effect.
Usage in examples
These utilities are demonstrated in the examples:- Interactive gestures - Uses
project()andmapRange()for gesture-driven animations - Picture-in-picture - Uses
project()for velocity-based snap targets
See also
- Gesture integration - Learn how to use these utilities with gestures
- SpringAnimator - The property-based animation API
- Wave.animate() - The block-based animation API