InteractionTracker.TryUpdatePositionWithAnimation 方法

定义

尝试通过应用动画来更新 InteractionTracker 的位置。

TryUpdatePositionWithAnimation 方法根据 CompositionAnimation 输入作为参数更新 InteractionTracker 的位置。 此方法用于需要由特定动画而不是传统的惯性体验定义的 InteractionTracker 运动的情况。 可以从空闲或惯性状态调用 TryUpdatePositionWithAnimation - 这样做, InteractionTracker 的位置将由定义的动画驱动,并进入 CustomAnimation 状态。

public:
 virtual int TryUpdatePositionWithAnimation(CompositionAnimation ^ animation) = TryUpdatePositionWithAnimation;
int TryUpdatePositionWithAnimation(CompositionAnimation const& animation);
public int TryUpdatePositionWithAnimation(CompositionAnimation animation);
function tryUpdatePositionWithAnimation(animation)
Public Function TryUpdatePositionWithAnimation (animation As CompositionAnimation) As Integer

参数

animation
CompositionAnimation

要应用于 InteractionTracker 的动画。

返回

Int32

int

返回请求 ID。 在状态转换时,导致状态更改的请求将包含在参数中。 这些 ID 将从 1 开始,并在应用程序的生存期内随着每次尝试调用而增加。

示例

void CustomAnimationForIT(Vector3 newPosition)
{
  // Create a cubic bezier easing function that will be used in the KeyFrames
  CompositionEasingFunction cubicBezier = _compositor.CreateCubicBezierEasingFunction(new Vector2(.17f, .67f), new Vector2(1f, 1f);

  // Create the Vector3 KFA
  Vector3KeyFrameAnimation kfa = _compositor.CreateVector3KeyFrameAnimation();
  kfa.Duration = TimeSpan.FromSeconds(3);

  // Create the KeyFrames
  kfa.InsertKeyFrame(1.0f, newPosition, cubicBezier);

  // Update InteractionTracker position using this animation
  _tracker.TryUpdatePositionWithAnimation(kfa);
}

注解

创建想要更新 InteractionTracker 位置的动画时,无需调用 StartAnimation。 通过 TryUpdatePositionWithAnimation 传入动画后,系统会在后台处理此问题。

定义动画以对 InteractionTracker 的位置进行动画处理时,请确保使用 Vector3KeyFrameAnimation 或解析为 Vector3 的 ExpressionAnimation

下表总结了在特定状态下调用此方法时的预期行为:

当前状态业务成效
闲置请求的动画从请求的属性开始,状态更改为 CustomAnimation
正在交互忽略请求
惯性请求的动画从请求的属性开始,状态更改为 CustomAnimation
CustomAnimation当前动画停止,新请求的动画在请求的属性上开始,状态重新进入 CustomAnimation

适用于