En WPF ¿Cómo se añaden función de aceleración a mi animación por detrás de código?

StackOverflow https://stackoverflow.com/questions/3719597

  •  03-10-2019
  •  | 
  •  

Pregunta

Estoy creando doubleAniation en el código y quiero añadir una función de aceleración a ella, así que ¿cómo lo hago?

¿Fue útil?

Solución

Así es como lo hago:

        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);

Otros consejos

No es necesario el uso DoubleAnimationUsingKeyFrames - se puede hacer con sólo 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);

Tengo averiguar por mí mismo. Yo estaba buscando Aliviar la propiedad, pero en realidad se llama KeySpline y tengo que usar DoubleAniamtionUsingKeyFrames lugar, para conseguir aliviar funcionalidad.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top