InteractionTracker.NaturalRestingPosition 属性

定义

InteractionTracker 的自然静息位置。

NaturalRestingPosition 属性是 InteractionTracker 将在不考虑边界或惯性修饰符的情况下停止的计算位置。 此属性通常适用于滚动体验中的虚拟化等操作,其中必须知道 InteractionTracker 停止的位置。 使用 NaturalRestingPosition 属性有两个main用例:在 InertiaStateEntered 事件参数中检索其当前值,或者在创建惯性修饰符等内容时在 ExpressionAnimation 中引用此属性。

public:
 property float3 NaturalRestingPosition { float3 get(); };
float3 NaturalRestingPosition();
public Vector3 NaturalRestingPosition { get; }
var vector3 = interactionTracker.naturalRestingPosition;
Public ReadOnly Property NaturalRestingPosition As Vector3

属性值

Vector3 Vector3

float3

InteractionTracker 的自然静息位置。

示例

// Listen for the InertiaStateEntered event, so can grab NaturalRestingPosition value.
public void InertiaStateEntered(InteractionTracker sender, InteractionTrackerInertiaStateEnteredArgs args)
{
  // Grab the NaturalRestingPosition out of the args when the event is fired. Now have access to calculated Natural Rest spot
  Vector3 naturalRest = args.NaturalRestingPosition;
}

// Reference the NaturalRestingPosition property in an expression for things like 	SnapPoints
void CreateBasicSnapPoint(float highBound, float lowBound)
{
  var snappoint = InteractionTrackerInertiaRestingValue.Create(_compositor);

  // Reference the NaturalRestingPosition of InteractionTracker in an ExpressionAnimation for conditional portion of an InertiaModifier.
  snappoint.Condition = _compositor.CreateExpressionAnimation("this.target.NaturalRestingPosition.Y >= 	lowBound && this.target.NaturalRestingPosition.Y < highBound ");

  snappoint.Condition.SetScalarParameter("lowBound", lowBound);
  snappoint.Condition.SetScalarParameter("highBound", highBound);

  // Snap to the highbound if condition met
  snappoint.RestingValue = _compositor.CreateExpressionAnimation("highBound");
  snappoint.RestingValue.SetScalarParameter("highBound", highBound);

  yInertiaModifier.Add(snappoint);

  _tracker.ConfigurePositionYInertiaModifiers(yInertiaModifier);
}

注解

上述代码片段中描述的两个用例是 NaturalRestingPosition 属性的主要用途。 尽管你可能想像引用任何其他 object.property 关系一样引用 InteractionTracker 之外的此属性,但你并不总是会获得最新的值。 在这种情况下,建议侦听 InertiaStateEntered 事件并从参数中获取最新值。

适用于