Share via


KeyFrameAnimation.Direction 属性

定义

动画的播放方向。

Direction 属性允许在动画的 IterationCount 大于 1 时,从头到尾、从结束到开始或从结束到开始之间交替来驱动动画。 这提供了一种自定义动画定义的简单方法。

public:
 property AnimationDirection Direction { AnimationDirection get(); void set(AnimationDirection value); };
AnimationDirection Direction();

void Direction(AnimationDirection value);
public AnimationDirection Direction { get; set; }
var animationDirection = keyFrameAnimation.direction;
keyFrameAnimation.direction = animationDirection;
Public Property Direction As AnimationDirection

属性值

动画的播放方向。

Windows 要求

设备系列
Windows 10 Anniversary Edition (在 10.0.14393.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v3.0 中引入)

示例

AnimationDirection 为 Normal

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is normal i.e. forward. 
    animation.Direction = AnimationDirection.Normal; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 为 Reverse

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is Reverse i.e. end to start. 
    animation.Direction = AnimationDirection.Reverse; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 为备用

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is alternate i.e. start to end and then end to start and so on. 
    animation.Direction = AnimationDirection.Alternate; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

AnimationDirection 为 AlternateReverse

class Direction 
{ 
  Direction(Compositor compositor, SpriteVisual heroVisual) 
  { 
    Vector3KeyFrameAnimation animation = compositor.CreateVector3KeyFrameAnimation(); 
    animation.InsertKeyFrame(0f, new Vector3(0f,0f,0f)); 
    animation.InsertKeyFrame(1f, new Vector3(20f,20f,0f)); 
    animation.Duration = TimeSpan.FromSeconds(0.25); 

    // Run animation for 4 times 
    animation.IterationCount = 4; 

    // Direction of animation is alternate-reverse i.e. end to start and then start to end and so on. 
    animation.Direction = AnimationDirection.AlternateReverse; 

    heroVisual.StartAnimation("Offset", animation); 
  } 
} 

注解

给定迭代计数为 3 的偏移动画和两个关键帧 (0 和 1) ,关键帧 0 的值为 Vector3 (5,5,5) ,对于关键帧 1,值为 Vector3 (20,20,20) ,下表显示了具有不同 Direction 值的动画行为。

方向动画行为
普通动画将从偏移值 Vector3 (5,5,5) 开始,并转到 Vector3 (20,20,20) ,始终从 (5,5,5) 开始重复 3 次。
Reverse动画将反向启动,偏移值 (20,20,20) ,并转到 (5,5,5) 重复 3 次,始终从 (20,20,20) 开始。
备用对于第一次迭代,动画将从偏移值 (5,5,5) 开始,然后转到 (20,20,20) 。 第二个迭代动画中,动画将从偏移值 (20,20,20) 开始,然后转到 (5,5,5) 。 在第三次(也是最后一次迭代)中,动画将从偏移量 (5,5,5) 开始,并转到 (20,20,20) 。
AlternateReverse对于第一次迭代,动画将从偏移值 (20,20,20) 开始,并转到 (5,5,5) 。 第二次迭代中,动画将从偏移值 (5,5,5) 开始,然后转到 (20、20、20) 。 在第三次也是最后一次迭代中,动画将从偏移量 (20、20、20) 开始,并转到 (5,5,5) 。

适用于