Vit*_*lij 1 wpf animation easing-functions
我在代码中创建doubleAniation,我想为它添加一个缓动函数,那我该怎么做呢?
没有必要使用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);
Run Code Online (Sandbox Code Playgroud)
我是这样做的:
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);
Run Code Online (Sandbox Code Playgroud)