X 和 Y 中的移动对象动画

本文关键字:移动 对象 动画 | 更新日期: 2023-09-27 17:56:01

我已经为X中的移动对象创建了动画,但是如何添加Y?

TranslateTransform trans = new TranslateTransform();
Pointer.RenderTransform = trans;
DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);

X 和 Y 中的移动对象动画

使用情节提要并将两个动画添加为子动画:

Storyboard storyBoard = new Storyboard
                    { Duration = new Duration(TimeSpan.FromMilliseconds(325)) };
DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim2, trans);
Storyboard.SetTargetProperty(anim2, new PropertyPath(TranslateTransform.XProperty));
DoubleAnimation anim1 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim1.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim1.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim1, trans);
Storyboard.SetTargetProperty(anim1, new PropertyPath(TranslateTransform.YProperty));
storyBoard.Children.Add(anim2);
storyBoard.Children.Add(anim1);
storyBoard.Begin();

想出了一个答案:

        TranslateTransform trans = new TranslateTransform();
        Pointer.RenderTransform = trans;
        DoubleAnimation animX = new DoubleAnimation(0, 750, TimeSpan.FromMilliseconds(325));
        DoubleAnimation animY = new DoubleAnimation(0, 100, TimeSpan.FromMilliseconds(325));
        animX.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
        animY.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
        animX.Completed += new EventHandler(myanim_Completed);
        trans.BeginAnimation(TranslateTransform.XProperty, animX);
        trans.BeginAnimation(TranslateTransform.YProperty, animY);