在WPF中,如何从后面的代码中将宽松功能添加到我的动画中?
-
03-10-2019 - |
题
我正在创建代码的双重保密,我想在其中添加一个宽松的功能,那么我该怎么做?
解决方案
这就是我的方式:
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);
其他提示
不必使用 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);
我自己弄清楚了。我当时正在寻找轻松的属性,但实际上它被称为Keyspline,我必须使用DoubleAniamTionusingKeyframes来获得宽松的功能。
不隶属于 StackOverflow