一个用 Swift 编写的跨平台缓动函数集合,不依赖于 SwiftUI 或 CoreGraphics。
// An ease-out curve
let unitCurve = EaseOutInEaseOut()
let unitY = unitCurve.value(at: 0.88)
| 类型 | EaseIn (缓入) |
EaseOut (缓出) |
EaseInEaseOut (缓入缓出) |
|---|---|---|---|
sine (正弦) |
![]() |
![]() |
![]() |
cubic (三次) |
![]() |
![]() |
![]() |
quint (五次) |
![]() |
![]() |
![]() |
circ (圆形) |
![]() |
![]() |
![]() |
quad (二次) |
![]() |
![]() |
![]() |
quart (四次) |
![]() |
![]() |
![]() |
expo (指数) |
![]() |
![]() |
![]() |
bounce (弹跳) |
![]() |
![]() |
![]() |
back (回弹) |
![]() |
![]() |
![]() |
elastic (弹性) |
![]() |
![]() |
![]() |
// An ease-out curve
let unitCurve = EaseOut(.cubic)
let unitY = unitCurve.value(at: 0.25)
// An ease-in-ease-out elastic curve
let unitY = easeInEaseOutElastic(at: 0.68)
一个三次贝塞尔曲线,第一个点 P0 为 (0.0, 0.0),最后一个点 P3 为 (1.0, 1.0)。
三次贝塞尔曲线由四个点定义:P0、P1、P2 和 P3。点 P0 和 P3 代表曲线的开始和结束。
P1 或 P2 坐标超出 [0, 1] 范围的三次贝塞尔曲线可能导致值超过最终状态,然后返回。
let unitCurve = CubicBezierCurve(x1: 0.1, y1: 0.6, x2: 0.7, y2: 0.2)
let unitY = unitCurve.value(at: 0.25)
线性曲线定义了沿 t 轴等间距的 Y 值。
线性曲线必须始终以 0.0 开始,以 1.0 结束。
let linear = Linear(values: [0.0, 0.25, 0.25, 1.0])
let unitY = linear.value(at: 0.25)
// An linear curve
let linear = Linear(values: [0.0, 0.1, 0.5, 0.9, 1.0])
let unitY = linear.value(at: 0.68)
跳转曲线定义阶跃函数,该函数将输出值域划分为等距阶跃
| 类型 | 图像 | 描述 |
|---|---|---|
jumpStart (起始跳转) |
![]() |
在 t=0.0 点跳转到第一个阶跃,最终阶跃位于 t=1.0。 |
jumpEnd (结束跳转) |
![]() |
在第一个阶跃的末尾跳转到第一个阶跃。 |
jumpNone (无跳转) |
![]() |
在第一个阶跃的末尾跳转到第一个阶跃,最终阶跃位于 1.0。 |
jumpBoth (双端跳转) |
![]() |
在 t=0 时跳转到第一个阶跃,最终阶跃位于 1.0。 |
let jump = Jump(.jumpEnd, steps: 4)
let unitY = jump.value(at: 0.25)
let jump = Jump(.jumpBoth, steps: 3)
let unitY = jump.value(at: 0.68)
MIT License
Copyright (c) 2024 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright © 2001 Robert Penner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.