有没有等价于FastOutSlowInInterpolator的适用于 iOS?我最近接触了 AndroidX,非常喜欢这个插值器。我找到了 source code也适用于它,但不知道如何将其转换为 iOS 实现。
最佳答案
如果您使用的是 UIViewPropertyAnimator
,则您需要的曲线是 .easeInOut ,并且您可以在创建动画器时将其作为 curve
参数传递:
let animator = UIViewPropertyAnimator(duration: 0.4, curve: .easeInOut) {
// Animations
}
如果对这个系统曲线不满意,可以关注this answer并使用 this handy website复制 FastOutSlowInInterpolator
的控制点。
作为FastOutSlowInInterpolator文档状态:
Interpolator corresponding to
fast_out_slow_in
. Uses a lookup table for the Bezier curve from (0,0) to (1,1) with control points: P0 (0, 0) P1 (0.4, 0) P2 (0.2, 1.0) P3 (1.0, 1.0)
因此,在您的特定情况下,您正在寻找这样的东西:
let timingParameters = UICubicTimingParameters(
controlPoint1: CGPoint(x: 0.4, y: 0),
controlPoint2: CGPoint(x: 0.2, y: 1)
)
let animator = UIViewPropertyAnimator(duration: 0.4, timingParameters: timingParameters)
或者这个:
let animator = UIViewPropertyAnimator(
duration: 0.4,
controlPoint1: CGPoint(x: 0.4, y: 0),
controlPoint2: CGPoint(x: 0.2, y: 1)
) {
// Animations
}
关于android - 是否有等效于 iOS 的 FastOutSlowInInterpolator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64438742/