跳至主内容
版本:当前版本

缓动函数

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

Easing 模块实现了常见的缓动函数。该模块被 Animated.timing() 用于在动画中呈现符合物理规律的运动效果。

您可以在 https://easings.net/ 查看常见缓动函数的可视化示例。

预定义动画​

Easing 模块通过以下方法提供了多种预定义动画效果:

  • back 提供基础回弹动画:物体先轻微后退再向前移动

  • bounce 提供弹跳动画效果

  • ease 提供基础惯性动画效果

  • elastic 提供基础弹簧交互效果

标准函数​

提供三种标准缓动函数:

poly 函数可用于实现四次方、五次方等更高阶幂函数。

附加函数​

以下方法提供了额外的数学函数:

  • bezier 提供三次贝塞尔曲线

  • circle 提供圆形函数

  • sin 提供正弦函数

  • exp 提供指数函数

以下辅助函数用于修改其他缓动函数:

  • in 正向执行缓动函数

  • inOut 使缓动函数呈现对称效果

  • out 反向执行缓动函数

示例​


参考

方法​

step0()​

tsx
static step0(n: number);

阶跃函数:当 n 为任意正值时返回 1


step1()​

tsx
static step1(n: number);

阶跃函数:当 n 大于或等于 1 时返回 1


linear()​

tsx
static linear(t: number);

线性函数:f(t) = t,位置与时间呈等比例关系

https://cubic-bezier.com/#0,0,1,1


ease()​

tsx
static ease(t: number);

基础惯性交互:模拟物体缓慢加速至目标速度的效果

https://cubic-bezier.com/#.42,0,1,1


quad()​

tsx
static quad(t: number);

二次函数:f(t) = t * t,位置等于时间的平方

https://easings.net/#easeInQuad


cubic()​

tsx
static cubic(t: number);

三次函数:f(t) = t * t * t,位置等于时间的立方

https://easings.net/#easeInCubic


poly()​

tsx
static poly(n: number);

幂函数。位置等于经过时间的 N 次方。

n = 4 对应:https://easings.net/#easeInQuart n = 5 对应:https://easings.net/#easeInQuint


sin()​

tsx
static sin(t: number);

正弦函数。

https://easings.net/#easeInSine


circle()​

tsx
static circle(t: number);

圆形函数。

https://easings.net/#easeInCirc


exp()​

tsx
static exp(t: number);

指数函数。

https://easings.net/#easeInExpo


elastic()​

tsx
static elastic(bounciness: number);

基础弹性交互效果,类似弹簧来回振荡。

默认弹性系数为 1(会产生小幅回弹),0 表示完全无回弹,N > 1 时会回弹约 N 次。

https://easings.net/#easeInElastic


back()​

tsx
static back(s)

配合 Animated.parallel() 使用,可创建物体在动画开始时轻微回缩的基础效果。


bounce()​

tsx
static bounce(t: number);

提供基础弹跳效果。

https://easings.net/#easeInBounce


bezier()​

tsx
static bezier(x1: number, y1: number, x2: number, y2: number);

提供三次贝塞尔曲线,等同于 CSS Transitions 的 transition-timing-function。

可视化工具:https://cubic-bezier.com/


in()​

tsx
static in(easing: number);

正向执行缓动函数。


out()​

tsx
static out(easing: number);

反向执行缓动函数。


inOut()​

tsx
static inOut(easing: number);

使缓动函数对称执行:前半个周期正向运行,后半个周期反向运行。