في WPF كيف يمكنني إضافة وظيفة التخفيف إلى الرسوم المتحركة الخاصة بي من الكود وراء؟
-
03-10-2019 - |
سؤال
أقوم بإنشاء DoubleAniation في التعليمات البرمجية وأريد إضافة وظيفة تخفيف ، فكيف أفعل ذلك؟
المحلول
إليك كيف أفعل ذلك:
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 وعلي استخدام Doubleaniamtionusingekeframes بدلاً من ذلك ، للحصول على وظائف التخفيف.
لا تنتمي إلى StackOverflow