CompositionObject.StartAnimationGroup(ICompositionAnimationBase) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
启动动画组。
CompositionObject 上的 StartAnimationGroup 方法可用于启动 CompositionAnimationGroup。 组中的所有动画将同时在 对象上启动。
public:
virtual void StartAnimationGroup(ICompositionAnimationBase ^ value) = StartAnimationGroup;
void StartAnimationGroup(ICompositionAnimationBase const& value);
public void StartAnimationGroup(ICompositionAnimationBase value);
function startAnimationGroup(value)
Public Sub StartAnimationGroup (value As ICompositionAnimationBase)
参数
要启动的动画组。
Windows 要求
设备系列 |
Windows 10 Anniversary Edition (在 10.0.14393.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v3.0 中引入)
|
示例
class PropertyAnimation
{
PropertyAnimation(Compositor compositor, SpriteVisual heroVisual)
{
// Define ImplicitAnimations
ImplicitAnimationCollection implicitAnimations = compositor.CreateImplicitAnimationCollection();
// Animate multiple properties on the target when the “Offset” property changes.
CompositionAnimationGroup animationGroup = compositor.CreateCompositionAnimationGroup();
animationGroup.Add(CreateSizeAnimation(compositor));
animationGroup.Add(CreateRotationAnimation(compositor));
// Set the CenterPoint so that rotation will be around the center
heroVisual.CenterPoint = new Vector3((heroVisual.Size.X/2.0f), (heroVisual.Size.Y/2.0f), 0.0f);
// Start AnimationGroup
heroVisual.StartAnimationGroup(animationGroup);
}
Vector2KeyFrameAnimation CreateSizeAnimation(Compositor compositor)
{
Vector2KeyFrameAnimation animation = compositor.CreateVector2KeyFrameAnimation();
CubicBezierEasingFunction easing = compositor.CreateCubicBezierEasingFunction(new Vector2(0.80f, 0.0f), new Vector2(0.95f, 1.0f));
// value (as the animation will target on the “Size” property).
animation.InsertExpressionKeyFrame(0f, "this.StartingValue", easing);
animation.InsertExpressionKeyFrame(1f, "this.StartingValue * 2", easing);
animation.Duration = TimeSpan.FromSeconds(0.25);
animation.Target = “Size”;
return animation;
}
ScalarKeyFrameAnimation CreateRotationAnimation(Compositor compositor)
{
ScalarKeyFrameAnimation animation = compositor.CreateScalarKeyFrameAnimation();
// Create KeyFrameAnimation to animate RotationAngleInDegrees by 90 degrees.
animation.InsertExpressionKeyFrame(0f, "this.StartingValue”);
animation.InsertExpressionKeyFrame(1f, "this.StartingValue + 90.0f”);
animation.Duration = TimeSpan.FromSeconds(0.25);
animation.Target = “RotationAngleInDegrees”;
return animation;
}
}
注解
StartAnimationGroup 采用 CompositionAnimationGroup 作为参数,在对象上同时启动组中的所有动画。 组中的 CompositionAnimation 应具有分配给 Target 属性的值。
若要获取所有动画的 Completed 事件,应从包含已注册 Completed 事件的CompositionScopedBatch 调用 StartAnimationGroup。