1

我在代码中创建 doubleAniation 并且我想向它添加一个缓动函数,那么我该怎么做呢?

4

3 回答 3

10

没有必要使用DoubleAnimationUsingKeyFrames- 只需DoubleAnimation

CircleEase easing = new CircleEase();  // or whatever easing class you want
easing.EasingMode = EasingMode.EaseInOut;
DoubleAnimation scrollQueue = new DoubleAnimation();
scrollQueue.By = -singleScrollAmt;
scrollQueue.EasingFunction = easing;
scrollQueue.Duration = TimeSpan.FromSeconds(0.5);
MyTextBlock.BeginAnimation(Canvas.TopProperty, scrollQueue);
于 2013-06-19T19:32:40.610 回答
5

这是我的做法:

        DoubleAnimationUsingKeyFrames compassRoseAnimation = new DoubleAnimationUsingKeyFrames();
        compassRoseAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));
        QuarticEase easingFunction = new QuarticEase();
        easingFunction.EasingMode = EasingMode.EaseInOut;
        EasingDoubleKeyFrame startAnimation = new EasingDoubleKeyFrame(previousRotationDegrees, KeyTime.FromPercent(0));
        EasingDoubleKeyFrame endAnimation = new EasingDoubleKeyFrame(newRotationDegrees, KeyTime.FromPercent(1.0), easingFunction);
        compassRoseAnimation.KeyFrames.Add(startAnimation);
        compassRoseAnimation.KeyFrames.Add(endAnimation);

        RotateTransform rotateTransform = new RotateTransform();
        CompassWithNumbersControl.RenderTransform = rotateTransform;
        rotateTransform.BeginAnimation(RotateTransform.AngleProperty, compassRoseAnimation);
于 2010-11-28T13:38:22.093 回答
-1

我自己已经弄清楚了。我一直在寻找 Easing 属性,但实际上它被称为 KeySpline,我必须改用 DoubleAniamtionUsingKeyFrames 来获得缓动功能。

于 2010-09-21T13:15:04.193 回答