共用方式為


KeyFrameAnimation.Direction 屬性

定義

動畫現正播放的方向。

Direction屬性可讓您在動畫的IterationCount大於一時,從開始到端或端對端之間或從頭到尾或開始之間替代來驅動動畫。 這可讓您輕鬆自訂動畫定義。

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 為 Alternate

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

備註

假設主要畫面格 0 的反覆運算計數為 3 和兩個主要畫面格的位移動畫 (0,而 1 個) 值為 Vector3 (5,5,5) ,而 Vector3 的值 (則為 20,20,20,20,20,20,20,20,1) ,下表顯示方向的不同值動畫行為。

方向動畫行為
正常動畫會從位移值 Vector3 (5,5,5) 開始,並移至 Vector3 (20,20,20) ,重複 3 次一律從 (5,5,5) 開始。
Reverse動畫會從 20,20,20,20) 開始反轉和位移 (值,並一律 (從 20,20,20,20) 開始重複 3 次 (5,5,5) 重複 3 次。
替代在第一次反覆運算中,動畫會從位移值 (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) 。

適用於