我有以下代码将矩形向下平移 100px,然后一旦完成将矩形向右平移100px,但我希望向右平移以保持动画 Y (100px),但它不会这样做。调试时,我注意到 Translation 的值是 (0,0,0) 而不是 (0,100,0)。
这是我在我的应用程序中的代码(应用程序需要有 UWP 目标 + 最小 sdk 17763):
public MainPage()
{
this.InitializeComponent();
this.Loaded += (sender1, e1) =>
{
var compositor = Window.Current.Compositor;
var batch = compositor.CreateScopedBatch(Windows.UI.Composition.CompositionBatchTypes.Animation);
var vertical = compositor.CreateVector3KeyFrameAnimation();
vertical.InsertKeyFrame(1.0f, new Vector3(0f, 100f, 0f));
vertical.Duration = TimeSpan.FromMilliseconds(2000);
vertical.Target = "Translation";
Rect.StartAnimation(vertical);
batch.End();
batch.Completed += (sender2, e2) =>
{
var horizontal = compositor.CreateVector3KeyFrameAnimation();
// PROBLEM: ... Rect.Translation.Y is not 100, it's 0 ...
horizontal.InsertKeyFrame(1.0f, new Vector3(100f, Rect.Translation.Y, 0f));
horizontal.Duration = TimeSpan.FromMilliseconds(2000);
horizontal.Target = "Translation";
Rect.StartAnimation(horizontal);
};
};
}
初始动画完成后保持 Y 位置的正确方法是什么?