在ios中使用关键帧动画时如何设置动画曲线? [英] how to set animation curve when using keyframe animation in ios?

查看:653
本文介绍了在ios中使用关键帧动画时如何设置动画曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用UIView的关键帧动画时设置动画曲线:

How to set animation curve when using UIView's keyframe animation :

animateKeyframesWithDuration:delay:options:animations:completion:

无论我在动画块中做什么似乎都是线性的(除非我使用 UIViewKeyframeAnimationOptionCalculationModeCubic 选项,但这不是我想要的。)

Whatever I do in the animation block seems to be linear (unless I use the UIViewKeyframeAnimationOptionCalculationModeCubic option but this isn't what I want).

我希望在动画上有一个缓出曲线,如<$使用常规动画时的c $ c> UIViewAnimationOptionCurveEaseOut 选项:

I'd like to have an ease out curve on the animation like the UIViewAnimationOptionCurveEaseOut option when using regular animation :

animateWithDuration:delay:options:animations:completion:


推荐答案

如果您使用的是关键帧,则必须自己定义曲线..如果添加线性关键帧,则会有线性动画。如果你添加非线性关键帧,你将有一个非线性动画。

If you are using keyframes, you have to define the curve on your own.. if you add linear keyframes, you have a linear animation. If you add non-linear keyframes, you will have a non-linear animation.

frameStartTime 是你的朋友这里......它们在关键帧之间总是线性的(或节奏/立方/立方节奏,如 UIViewKeyframeAnimationOptionCalculationMode 中定义的那样)

The frameStartTime is your friend here... it will always be linear between keyframes (or paced / cubic / cubic paced, like defined in the UIViewKeyframeAnimationOptionCalculationMode)

UIViewKeyframeAnimationOptionCalculationModeLinear     = 0 << 9,
UIViewKeyframeAnimationOptionCalculationModeDiscrete   = 1 << 9,
UIViewKeyframeAnimationOptionCalculationModePaced      = 2 << 9,
UIViewKeyframeAnimationOptionCalculationModeCubic      = 3 << 9,
UIViewKeyframeAnimationOptionCalculationModeCubicPaced = 4 << 9

要计算正确的时间值,您可以将其作为参考:
RBBEasingFunction

To calculate correct timing values, you could use this as a reference: RBBEasingFunction

EG EaseInOutQuad 喜欢这样(其中t是动画中的相对时间):

E.g. EaseInOutQuad like this (where t is the relative time within the animation):

if (t < 0.5) {
    return 2 * t * t;
} else {
    return -1 + (4 - 2 * t) * t;
}

这篇关于在ios中使用关键帧动画时如何设置动画曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆